F
Filament13mo ago
X7Ryan

Define Form Data Mutation in One Place?

Quick question. I have a simple resource (using modals for creating and editing) and I need to mutate the data from the form before it is saved. I know I can pass a closure to mutateFormDataUsing() from the create/edit actions but that requires me to define the mutation in 3 places (the edit action, the create action on the manage page, and the create action under the empty state actions). Is there a way to define it once to apply to all create/edit actions (like maybe defining it under the field itself in the form schema definition?)
2 Replies
X7Ryan
X7RyanOP13mo ago
Looks like I could just hook into the field's dehydration and modify it there. https://filamentphp.com/docs/3.x/forms/advanced#field-dehydration
DrByte
DrByte13mo ago
Or, if the mutation is something you need to enforce at the Model level, you could use Laravel observers or event hooks on the model.

Did you find this page helpful?