Dual display of notifications
I am fulfilling a validation before updating a record, if the condition on an allowed restriction, an error is displayed and the record is not updated.
I'm doing this in beforeSave(), the record does not actually update but I have a duplicate notification, the expected error and the project's default success.
Does anyone know how to treat this?
Code:
protected function beforeSave()
{
if(isset($this->record->status) && $this->record->status == 'In production') {
$noworking = new WorkingDays();
$check = $noworking->noWorking($this->record->wait_date_at);
if($check) {
// return error
return Notification::make()
->title('OPS!')
->body('Error')
->danger()
->seconds(10)
->send();
}
}
}
4 Replies
Hi @josecaubivasconcelosjunior.
I may be wrong, but it seems to be that you'll need to throw an exception for that to work as you expect.
In the EditRecord base class, line 104 calls the beforeSave hook, but if it just returns a notification, the save() method won't halt (line 109).
And... I'm wrong. hahahah
I've tested this approach but it does not work.
Thank you for your reply friend.
I managed to solve it with $this->halt(), following the documentation
https://filamentphp.com/docs/2.x/admin/resources/editing-records
#Halting the saving process
Filament
Editing records - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
This interrupts the life cycle of the process at any time, I changed the method from beforeSave to beforeValidate, just to be more coherent, without a real need to change π
Awesome, I've tried this in my application and it worked as well. Good job