milwad-dev /
laravel-validate
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Milwad\LaravelValidate\Rules; |
||
| 4 | |||
| 5 | use Illuminate\Contracts\Validation\Rule; |
||
| 6 | |||
| 7 | class ValidDuplicateCharacter implements Rule |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Check duplicate characters, splitted by comma. |
||
| 11 | */ |
||
| 12 | public function passes($attribute, $value): bool |
||
| 13 | { |
||
| 14 | $value = explode(',', $value); |
||
| 15 | |||
| 16 | return collect($value)->duplicates()->isEmpty(); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 17 | } |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Get the validation error message. |
||
| 21 | */ |
||
| 22 | public function message(): string |
||
| 23 | { |
||
| 24 | return __('validate.duplicate_character'); |
||
| 25 | } |
||
| 26 | } |
||
| 27 |