Customizing data before saving
Sometimes, you may wish to modify form data before it is finally saved to the database. To do this, you may define amutateFormDataBeforeCreate() method on the Create page class, which accepts the $data as an array, and returns the modified version:
Customizing the creation process
You can tweak how the record is created using thehandleRecordCreation() method on the Create page class:
Customizing form redirects
By default, after saving the form, the user will be redirected to the Edit page of the resource, or the View page if it is present. You may set up a custom redirect when the form is saved by overriding thegetRedirectUrl() method on the Create page class.
For example, the form can redirect back to the List page:
Customizing the save notification
When the record is successfully created, a notification is dispatched to the user, which indicates the success of their action. To customize the title of this notification, define agetCreatedNotificationTitle() method on the create page class:
getCreatedNotification() method on the create page class:
null from the getCreatedNotification() method on the create page class:
Lifecycle hooks
Hooks may be used to execute code at various points within a page’s lifecycle, like before a form is saved. To set up a hook, create a protected method on the Create page class with the name of the hook:beforeCreate() method will be called before the data in the form is saved to the database.
There are several available hooks for the Create page:
Halting the creation process
At any time, you may call$this->halt() from inside a lifecycle hook or mutation method, which will halt the entire creation process:
cancel() the action instead of halting it:
Authorization
For authorization, Filament will observe any model policies that are registered in your app. Users may access the Create page if thecreate() method of the model policy returns true.
Wizards
You may easily transform the creation process into a multistep wizards. On the page class, add the correspondingHasWizard trait:
getSteps() array, return your wizard steps:
steps() array and pass your Step objects:
hasSkippableSteps() method:
Sharing fields between the resource form and wizards
If you’d like to reduce the amount of repetition between the resource form and wizard steps, it’s a good idea to extract public static resource functions for your fields, where you can easily retrieve an instance of a field from the resource or the wizard:Custom view
For further customization opportunities, you can override the static$view property on the page class to a custom view in your app: