mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-11 02:11:05 +03:30
30 lines
755 B
PHP
30 lines
755 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use App\Models\Label;
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
class ValidEnabledLabels implements ValidationRule
|
|
{
|
|
/**
|
|
* Run the validation rule.
|
|
*
|
|
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
$formattedVal = pluckValues($value,'id');
|
|
$validIds = Label::whereIn('id', $formattedVal)
|
|
->where('enabled', true)
|
|
->pluck('id')
|
|
->toArray();
|
|
|
|
if(count(array_diff($formattedVal, $validIds)) !== 0)
|
|
{
|
|
$fail('the :attribute must be enabled.');
|
|
}
|
|
}
|
|
}
|