Observe form builder save and update actions
I'm trying the filament and I think it's amazing.
But I have a problem, I can't find it in the documentation or in the topics of this channel.
If there is already a solution that I haven't found, I apologize.
I want to be able to observe the save and update actions of my form builder, so I can do auxiliary actions like sending an email.
Is it possible to do something like this?
9 Replies
Hi @josecaubivasconcelosjunior, this will depend on the kind of action you want to do but maybe lifecycle hooks can be useful :
https://filamentphp.com/docs/2.x/admin/resources/creating-records#lifecycle-hooks
Filament
Creating records - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
afterCreate()
afterSave()
etc.Oh!!
Thank you very much!! I was literally focusing my attention on the form builder documentation.
Forgive me for making you point out something so obvious.
No worries, it is specific to the Admin panel so it's easy to miss đ
One question, can't I use 'protected function afterCreate(): void' when I have my form built in my class using extends Resource?
Do I necessarily need to extend CreateRecord?
My form builder is done as follows.
class VehicleResource extends Resource
{
public static function form(Form $form): Form
{
return $form
->schema([
// ........
]);
}
No, you need to use those methods in the CreateVehicle class. They canât be used in VehicleResource. CreateVehicle should have been created automatically if you are using Filamentâs artisan command to generate resources
I can understand, but I think I did something different than expected in creating the resources, I generated them as follows.
php artisan make:filament-resource Vehicle --generate --simple
I noticed that something similar to what you suggested was the 'ManageVehicle' file, which is in the path 'App\Filament\Resources\VehicleResource\Pages'
It just depends on what you want. If you want need relation managers youâll have to use a normal resource.
And if you want to use the simple then just use that method in the ManagesVehicle class
The relationship part I managed to overcome the obstacles, what I need at the moment is very simple in theory.
I just want to identify a record action in the database and do extra actions similar to the notification feature of the filament.
For example, send an email after creating a record.
I thought exactly about this possibility, your answer helped me to realize this path
Recreating without using the --simple flag, just following the documentation recommendation
php artisan make:filament-resource Customer --generate
I was easily able to use
protected function afterCreate(): void
I was able to reuse all the codes already made for form and table.
Thank you for your help.