Forms\Components\Select::make('time_id')
->label('Time')
->relationship(name: 'time', titleAttribute: 'name')
->disableOptionWhen(function (string $value, Get $get, string $operation,string $state): bool {
$findSlotNotAvailable = Slot::where('date', $get('date'))->get()->pluck('time_id')->toArray();
if($operation == 'edit'){
return in_array($value, $findSlotNotAvailable) && $value != $state;
}
return in_array($value, $findSlotNotAvailable);
})
->rules([
fn (Get $get, string $operation,string $state): Closure => function (string $attribute, $value, Closure $fail) use($get, $operation,$state) {
$findSlotNotAvailable = Slot::where('date', $get('date'))->get()->pluck('time_id')->toArray();
if($operation == 'edit'){
if(in_array($value, $findSlotNotAvailable) && $value != $state){
$fail('The :attribute is not available.');
};
}else{
if(in_array($value, $findSlotNotAvailable)){
$fail('The :attribute is not available.');
};
}
},
])
->required(),Filament select custom validation
by
Tags:
Leave a Reply