HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/ghayatcom/ghayatcom-api/app/Rules/CommaSeparatorCount.php
<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

/**
 * App\Rules
 *
 * @property string $name
 */
class CommaSeparatorCount implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct($name)
    {
        $this->name = $name;
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  string  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        if ((! empty($this->name)) || (! empty($value))) {
            if (isset($this->name)) {
                $nameExplode = explode(',', $this->name);
            } else {
                $nameExplode = [];
            }
            $nameCount = count(array_filter($nameExplode));
            $valueCount = count(explode(',', $value));
            $sum = $valueCount + $nameCount;
            /** @var integer $sum */
            return ($sum != 0) ? true : false;
        } else {
            return true;
        }
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute must be minimum 2.';
    }
}