> ## Documentation Index
> Fetch the complete documentation index at: https://filament-34a8cf01.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Viewing records

> [!WARNING]
>
> You are currently viewing the documentation for Filament 2.x, which is a previous version of Filament.
>
> Looking for the current stable version? Visit the [5.x documentation](https://filament-34a8cf01.mintlify.site/5.x).

## Creating a resource with a View page

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

```bash theme={"theme":"gruvbox-dark-hard"}
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:

```bash theme={"theme":"gruvbox-dark-hard"}
php artisan make:filament-page ViewUser --resource=UserResource --type=ViewRecord
```

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

```php theme={"theme":"gruvbox-dark-hard"}
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'),
    ];
}
```

## Viewing records in modals

If your resource is simple, you may wish to view records in modals rather than on the [View page](https://filament-34a8cf01.mintlify.site/2.x/admin/resources/viewing-records.md). If this is the case, you can just [delete the view page](https://filament-34a8cf01.mintlify.site/2.x/admin/resources/getting-started.md#deleting-pages).

If your resource doesn't contain a `ViewAction`, you can add one to the `$table->actions()` array:

```php theme={"theme":"gruvbox-dark-hard"}
use Filament\Resources\Table;
use Filament\Tables;

public static function table(Table $table): Table
{
    return $table
        ->columns([
            // ...
        ])
        ->actions([
            Tables\Actions\ViewAction::make(),
            // ...
        ]);
}
```

## 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 View page class to modify the `$data` array, and return the modified version before it is filled into the form:

```php theme={"theme":"gruvbox-dark-hard"}
protected function mutateFormDataBeforeFill(array $data): array
{
    $data['user_id'] = auth()->id();

    return $data;
}
```

Alternatively, if you're viewing records in a modal action:

```php theme={"theme":"gruvbox-dark-hard"}
use Filament\Tables\Actions\ViewAction;

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

        return $data;
    })
```

## Authorization

For authorization, Filament will observe any [model policies](https://laravel.com/docs/authorization#creating-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:

```php theme={"theme":"gruvbox-dark-hard"}
protected static string $view = 'filament.resources.users.pages.view-user';
```

[Edit this page on GitHub](https://github.com/filamentphp/filament/edit/2.x/packages/admin/docs/02-resources/05-viewing-records.md)

## Sponsored by

[Your logo here](https://github.com/sponsors/danharrin)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.