You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello everyone. I made a custom rule. If the driver has an active shift, then you can't change the driver in select. Everything works fine, if I change to another driver, then I get an error.
But if I delete the driver through the standard delete icon, then there is no error.
The rule does not work. Thanks for your help
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('driver_id')
->label('Водитель')
->relationship(
'driver',
'first_name',
modifyQueryUsing: function (Builder $query, ?Car $record) {
$query
->when($record, fn (Builder $query) => $query->whereId($record->driver_id))
->orWhere(fn (Builder $query) => $query->whereDoesntHave('car'));
}
)
->searchable()
->preload()
->reactive()
->live()
->afterStateUpdated(function (
$state,
$record,
callable $set,
Forms\Contracts\HasForms $livewire,
Forms\Components\Select $component
) {
$livewire->validateOnly($component->getStatePath());
$set('is_available', !$state);
if ($record) {
if ($state) {
$record->assignDriver($state);
} else {
$record->removeDriver();
}
}
})
->rules([
function ($get, $set, $record) {
return function (string $attribute, $value, Closure $fail) use ($record) {
if (!$record) {
return;
}
if ($record->driver_id == $value) {
return;
}
$oldDriver = $record->driver;
if ($oldDriver && $oldDriver->is_shift) {
$fail('You cannot change a driver while the current driver has an active shift.');
}
};
}
]),
Forms\Components\Toggle::make('is_available')
->required()
->default(true)
->disabled(),
]);
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Package
Panel builder
Package Version
3.3.0
How can we help you?
Hello everyone. I made a custom rule. If the driver has an active shift, then you can't change the driver in select. Everything works fine, if I change to another driver, then I get an error.
But if I delete the driver through the standard delete icon, then there is no error.
The rule does not work. Thanks for your help
`
Beta Was this translation helpful? Give feedback.
All reactions