Creating records
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 a mutateFormDataBeforeCreate() method on the Create page class, which accepts the $data as an array, and returns the modified version:
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['user_id'] = auth()->id();
return $data;
}
Alternatively, if you're creating records in a modal action, check out the Actions documentation.
Customizing the creation process
You can tweak how the record is created using the handleRecordCreation() method on the Create page class:
use Illuminate\Database\Eloquent\Model;
protected function handleRecordCreation(array $data): Model
{
return static::getModel()::create($data);
}
Alternatively, if you're creating records in a modal action, check out the Actions documentation.