Listing Records

Resources

Columns

The $table->columns() method is used to define the columns in your table. It is an array of column objects, in the order they should appear in your table.

We have many fields available for your forms, including:

To view a full list of available table columns, see the Table Builder documentation.

You may also build your own completely custom table columns.

Sorting a column by default

If a column is sortable(), you may choose to sort it by default using the $table->defaultSort() method:

use Filament\Resources\Table;
use Filament\Tables;
 
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')->sortable(),
// ...
])
->defaultSort('name');
}

Filters

Filters are predefined scopes that administrators can use to filter records in your table. The $table->filters() method is used to register these.

Displaying filters above the table content

To render the filters above the table content instead of in a popover, you may use:

use Filament\Tables\Filters\Layout;
use Filament\Resources\Table;
 
public static function table(Table $table): Table
{
return $table
->columns([
// ...
])
->filters(
[
// ...
],
layout: Layout::AboveContent,
);
}

Actions

Actions are buttons that are rendered at the end of table rows. They allow the user to perform a task on a record in the table. To learn how to build actions, see the full actions documentation.

To add actions to a table, use the $table->actions() method:

use Filament\Resources\Table;
use Filament\Tables;
 
public static function table(Table $table): Table
{
return $table
->columns([
// ...
])
->actions([
// ...
Tables\Actions\Action::make('activate')
->action(fn (Post $record) => $record->activate())
->requiresConfirmation()
->color('success'),
]);
}

Grouping actions

You may use an ActionGroup object to group multiple table actions together in a dropdown:

use Filament\Resources\Table;
use Filament\Tables;
 
public static function table(Table $table): Table
{
return $table
->columns([
// ...
])
->actions([
Tables\Actions\ActionGroup::make([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
]),
]);
}

Bulk actions

Bulk actions are buttons that are rendered in a dropdown in the header of the table. They appear when you select records using the checkboxes at the start of each table row. They allow the user to perform a task on multiple records at once in the table. To learn how to build bulk actions, see the full actions documentation.

To add bulk actions before the "Delete selected" action, use the $table->prependBulkActions() method:

use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Collection;
 
public static function table(Table $table): Table
{
return $table
->columns([
// ...
])
->bulkActions([
// ...
Tables\Actions\BulkAction::make('activate')
->action(fn (Collection $records) => $records->each->activate())
->requiresConfirmation()
->color('success')
->icon('heroicon-o-check'),
]);
}

Creating records in modals

If your resource is simple, you may wish to create records in a modal rather than on the Create page.

If you set up a modal resource you'll already be able to do this. But, if you have a normal resource and want to open a modal for creating records, delete the resource's Create page.

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 use the mutateFormDataUsing() method, which accepts the $data as an array, and returns the modified version:

use Filament\Tables\Actions\CreateAction;
 
CreateAction::make()
->mutateFormDataUsing(function (array $data): array {
$data['user_id'] = auth()->id();
 
return $data;
})

Customizing the creation process

You can tweak how the record is created using the process() method:

use Filament\Tables\Actions\CreateAction;
use Illuminate\Database\Eloquent\Model;
 
CreateAction::make()
->process(function (array $data): Model {
return static::getModel()::create($data);
})

Customizing the save notification

When the record is successfully created, a notification is dispatched to the user, which indicates the success of their action.

To customize the text content of this notification:

use Filament\Tables\Actions\CreateAction;
 
CreateAction::make()
->successNotificationMessage('User registered')

And to disable the notification altogether:

use Filament\Tables\Actions\CreateAction;
 
CreateAction::make()
->successNotificationMessage(null)

Lifecycle hooks

Hooks may be used to execute code at various points within an action's lifecycle.

use Filament\Tables\Actions\CreateAction;
 
CreateAction::make()
->beforeFormFilled(function () {
// Runs before the form fields are populated with their default values.
})
->afterFormFilled(function () {
// Runs after the form fields are populated with their default values.
})
->beforeFormValidated(function () {
// Runs before the form fields are validated when the form is submitted.
})
->afterFormValidated(function () {
// Runs after the form fields are validated when the form is submitted.
})
->before(function () {
// Runs before the form fields are saved to the database.
})
->after(function () {
// Runs after the form fields are saved to the database.
})

Editing records in modals

If your resource is simple, you may wish to edit records a modal rather than on the Edit page.

If you set up a modal resource you'll already be able to do this. But, if you have a normal resource and want to open a modal for editing records, delete the resource's Edit page.

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:

use Filament\Tables\Actions\EditAction;
 
EditAction::make()
->mutateRecordDataUsing(function (array $data): array {
$data['user_id'] = auth()->id();
 
return $data;
})

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 mutateFormDataUsing() method, which accepts the $data as an array, and returns it modified:

use Filament\Tables\Actions\EditAction;
 
EditAction::make()
->mutateFormDataUsing(function (array $data): array {
$data['last_edited_by_id'] = auth()->id();
 
return $data;
})

Customizing the saving process

You can tweak how the record is updated using the process() method:

use Filament\Tables\Actions\EditAction;
use Illuminate\Database\Eloquent\Model;
 
EditAction::make()
->process(function (Model $record, array $data): Model {
$record->update($data);
 
return $record;
})

Customizing the save notification

When the record is successfully updated, a notification is dispatched to the user, which indicates the success of their action.

To customize the text content of this notification:

use Filament\Tables\Actions\EditAction;
 
EditAction::make()
->successNotificationMessage('User updated')

And to disable the notification altogether:

use Filament\Tables\Actions\EditAction;
 
EditAction::make()
->successNotificationMessage(null)

Lifecycle hooks

Hooks may be used to execute code at various points within an action's lifecycle.

use Filament\Tables\Actions\EditAction;
 
EditAction::make()
->beforeFormFilled(function () {
// Runs before the form fields are populated from the database.
})
->afterFormFilled(function () {
// Runs after the form fields are populated from the database.
})
->beforeFormValidated(function () {
// Runs before the form fields are validated when the form is saved.
})
->afterFormValidated(function () {
// Runs after the form fields are validated when the form is saved.
})
->before(function () {
// Runs before the form fields are saved to the database.
})
->after(function () {
// Runs after the form fields are saved to the database.
})

Viewing records in modals

If your resource is simple, you may wish to view records in modals rather than on the View page. If this is the case, you can just delete the view page.

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

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

Deleting records

By default, you can bulk-delete records in your table. You may also wish to delete single records, using a DeleteAction:

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

Authorization

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

Users may access the List page if the viewAny() method of the model policy returns true.

They also have the ability to bulk-delete records if the deleteAny() method of the policy returns true. Filament uses the deleteAny() method because iterating through multiple records and checking the delete() policy is not very performant.

Customising the Eloquent query

Although you can customise the Eloquent query for the entire resource, you may also make specific modifications for the List page table. To do this, override the getTableQuery() method on the page class:

protected function getTableQuery(): Builder
{
return parent::getTableQuery()->withoutGlobalScopes();
}

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.list-users';

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