Courses

Filament 3 From Scratch: Practical Course

Restrict Add/Edit/Delete Actions and Buttons

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Restricting CRUD actions
- Implementing user permissions
- Using Laravel policies
- Managing access control

Video Version of the Lesson

[Only for premium members]

Link to the repository

[Only for premium members]

Text Version of the Lesson

In this lesson, let's look at simple ways to hide action buttons from the Filament table.


Restrict Create/Delete on Users

Let's imagine we have a User Management section, but we can't create a new user (they register themselves) or delete the existing one (for history archive reasons). The only thing we can do is edit the user's data.

So, I've generated a resource:

php artisan make:filament-resource User

And added a few columns to the form/table:

app/Filament/Resources/UserResource.php:

class UserResource extends Resource
{
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name'),
Forms\Components\TextInput::make('email')
->email(),
]);
}
 
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('email'),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}
 
public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
}

Visually it looks like this:

Now, let's remove the ability to Add and Delete users.


Restrict Adding New Records

To hide the Create form and all links to it, we need to make four changes:

Step 1. Resource method getPages(): delete the create page.

return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];

Step 2. In the Resource Table, remove the...

The full lesson is only for Premium Members.
Want to access all 24 video+text lessons of this course? (2 h 01 min)

You also get:

  • 80 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord