mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 19:41:07 +03:30
add validation for enabled labels, rename enable (to enabled) in labels table, and update the enabled attribute of corresponding labels to false when cycle saved
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user