Version

Theme

Actions - Prebuilt Actions

View action

Overview

Filament includes a prebuilt action that is able to view Eloquent records. When the trigger button is clicked, a modal will open with information inside. Filament uses form fields to structure this information. All form fields are disabled, so they are not editable by the user. You may use it like so:

use Filament\Actions\ViewAction;
use Filament\Forms\Components\TextInput;
 
ViewAction::make()
->record($this->post)
->form([
TextInput::make('title')
->required()
->maxLength(255),
// ...
])

If you want to view table rows, you can use the Filament\Tables\Actions\ViewAction instead:

use Filament\Forms\Components\TextInput;
use Filament\Tables\Actions\ViewAction;
use Filament\Tables\Table;
 
public function table(Table $table): Table
{
return $table
->actions([
ViewAction::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:

ViewAction::make()
->mutateRecordDataUsing(function (array $data): array {
$data['user_id'] = auth()->id();
 
return $data;
})
Edit on GitHub

Still need help? Join our Discord community or open a GitHub discussion