F
Filament9mo ago
Noxo

EditAction hooks

does EditAction have hooks like these: afterCreate, afterSave, beforeValidate? Filament\Tables\Actions\EditAction
Solution:
Sorry for my carelessness, it turns out there are all the necessary hooks there. I found them in the HasLifecycleHooks trait. But they are not in the documentation of version 3, only in version 2....
No description
Jump to solution
7 Replies
Noxo
Noxo9mo ago
Sorry for not specifying, I mean when there are no creation and editing pages. When everything happens in modal. In my case, I need the beforeValidate hook, because this is the only hook that fires before the relationships are saved/created. (at least that’s how it works within a page)
toeknee
toeknee9mo ago
Even without the page beforeValidate should still be called as it should be on the parent action if memory serves correctly. Are you wanting to intercept / write to it? You could try adding it to the resource, I think the pages extend the resource which contain the hooks
Noxo
Noxo9mo ago
the pages extend resource pages not resource. these pages are contain the hooks: Filament\Resources\Pages\CreateRecord Filament\Resources\Pages\EditRecord I researched actions but didn't find any hooks. I'm wondering if it's just me or other developers who need these hook? I can implement it and send PR 🤔
Tables\Actions\EditAction::make()
->afterCreate(fn () => '')
->beforeValidate(fn () => '')
->afterSave(fn () => '')
Tables\Actions\EditAction::make()
->afterCreate(fn () => '')
->beforeValidate(fn () => '')
->afterSave(fn () => '')
toeknee
toeknee9mo ago
Ahh ok that makes sense, please feel free to do a PR if you are sure. I haven't had chance to review the sub classes. But I see no reason why Dan wouldn't want them on actions too.
Solution
Noxo
Noxo9mo ago
Sorry for my carelessness, it turns out there are all the necessary hooks there. I found them in the HasLifecycleHooks trait. But they are not in the documentation of version 3, only in version 2.
No description
toeknee
toeknee9mo ago
No problem at alll. Always recommend using an IDE to test a theory too. Like phpStorm will show you all available methods on that class that are inherited or traited etc.