Editing records
Customizing data before filling the form
You may wish to modify the data from a record before it is filled into the form. To do this, you may define a mutateFormDataBeforeFill()
method on the Edit page class to modify the $data
array, and return the modified version before it is filled into the form:
protected function mutateFormDataBeforeFill(array $data): array
{
$data['user_id'] = auth()->id();
return $data;
}
Alternatively, if you're editing records in a modal action, check out the Actions documentation.
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 mutateFormDataBeforeSave()
method on the Edit page class, which accepts the $data
as an array, and returns it modified:
protected function mutateFormDataBeforeSave(array $data): array
{
$data['last_edited_by_id'] = auth()->id();
return $data;
}
Alternatively, if you're editing records in a modal action, check out the Actions documentation.