Overview
Filament includes a prebuilt action that is able to create Eloquent records. When the trigger button is clicked, a modal will open with a form inside. The user fills the form, and that data is validated and saved into the database. You may use it like so:Filament\Tables\Actions\CreateAction:
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 use themutateFormDataUsing() method, which has access to the $data as an array, and returns the modified version:
Customizing the creation process
You can tweak how the record is created with theusing() method:
$model is the class name of the model, but you can replace this with your own hard-coded class if you wish.
Redirecting after creation
You may set up a custom redirect when the form is submitted using thesuccessRedirectUrl() method:
$record parameter:
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, use thesuccessNotificationTitle() method:
successNotification() method:
successNotification(null) method:
Lifecycle hooks
Hooks may be used to execute code at various points within the action’s lifecycle, like before a form is saved. There are several available hooks:Halting the creation process
At any time, you may call$action->halt() from inside a lifecycle hook or mutation method, which will halt the entire creation process:
cancel() the action instead of halting it:
Using a wizard
You may easily transform the creation process into a multistep wizard. Instead of using aform(), define a steps() array and pass your Step objects:
skippableSteps() method:
Disabling create another
If you’d like to remove the “create another” button from the modal, you can use thecreateAnother(false) method: