Viewing Records

Resources

Creating a resource with a View page

To create a new resource with a View page, you can use the --view flag:

php artisan make:filament-resource User --view

Adding a View page to an existing resource

If you want to add a View page to an existing resource, create a new page in your resource's Pages directory:

php artisan make:filament-page ViewUser --resource=UserResource --type=ViewRecord

You must register this new page in your resource's getPages() method:

public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'view' => Pages\ViewUser::route('/{record}'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}

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 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;
}

Authorization

For authorization, Filament will observe any model policies that are registered in your app.

Users may access the View page if the view() method of the model policy returns true.

Custom view

For further customization opportunities, you can override the static $view property on the page class to a custom view in your app:

protected static string $view = 'filament.resources.users.pages.view-user';

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

Enjoying Filament?

We are open source at heart. To allow us to build new features, fix bugs, and run the community, we require your financial support.

Sponsor Filament on GitHub