Edit action
Overview
Filament includes a prebuilt action that is able to edit 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:
use Filament\Actions\EditAction;
use Filament\Forms\Components\TextInput;
EditAction::make()
->record($this->post)
->form([
TextInput::make('title')
->required()
->maxLength(255),
// ...
])
If you want to edit table rows, you can use the Filament\Tables\Actions\EditAction
instead:
use Filament\Forms\Components\TextInput;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->actions([
EditAction::make()
->form([
TextInput::make('title')
->required()
->maxLength(255),
// ...
]),
]);
}
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 use the mutateRecordDataUsing()
method to modify the $data
array, and return the modified version before it is filled into the form:
EditAction::make()
->mutateRecordDataUsing(function (array $data): array {
$data['user_id'] = auth()->id();
return $data;
})