F
Filament4mo ago
CGM

Is there a unified place for mutateFormDataBeforeCreate() and mutateFormDataBeforeSave()?

I have some logic that I would like to run on both save and create for a specific field when it is being saved. Is there a unified place, for example in the resource class that runs on both new saves and on edit saves to keep code a bit cleaner?
8 Replies
awcodes
awcodes4mo ago
I would just make a trait that can be applied to any create or edit record page. Could potentially macro or globally configure the field type to handle the dehydrateStateUsing() modifier. But I think the trait would be safer unless you make a custom field.
CGM
CGM4mo ago
I think you're right. A custom field may just be the way to go here though. This field is getting a little complex. Thank you @awcodes
awcodes
awcodes4mo ago
Even if it’s custom, it can still extend an existing one too, so you don’t necessarily have to re-invent the wheel either.
CGM
CGM4mo ago
I could extend the base Select field? If not too much to ask, are you aware of any docs on extending or projects that might do that, that I could source dive? That sounds like a fantastic option.
awcodes
awcodes4mo ago
Check out my table repeater plugin it extends filament’s repeater with a few custom modifiers and a custom views but still uses all the default repeater class functionality.
awcodes
awcodes4mo ago
GitHub
GitHub - awcodes/filament-table-repeater: A modified version of the...
A modified version of the Filament Forms Repeater to display it as a table. - awcodes/filament-table-repeater
awcodes
awcodes4mo ago
But yea. It’s all just OOP Based on what you’ve said you could probably just use the default view too. I’d start with the setUp method on the fields and go from there.
CGM
CGM4mo ago
You're amazing @awcodes , I really appreciate your help and time!
Want results from more Discord servers?
Add your server