Search code examples
laravellaravel-filamentlaravel-11filamentphp

Disable Edit or Delete for specific record in Filament Laravel


In a model, I have 2 specific columns named 'is_editable' and 'is_deletable' (both are boolen). In filament table, while showing record, I want to disable Edit and/or Delete buttons if 'is_editable' and/or 'is_deletable' set to false. I don't know how to do this. Can anybody help me solving this ?

[Please see table picture here](https://i.sstatic.net/8WSrvCTK.png)

Searched Filament document


Solution

  • You can use hidden() or disabled() methods on your table action, and make them dynamic by injecting $record in the function, like this:

    Tables\Actions\DeleteAction::make()
       ->disabled(fn($record) => !$record->is_deletable),
    Tables\Actions\EditAction::make()
       ->disabled(fn($record) => !$record->is_editable),
    

    Same is for hidden:

    Tables\Actions\DeleteAction::make()
       ->hidden(fn($record) => !$record->is_deletable),
    Tables\Actions\EditAction::make()
       ->hidden(fn($record) => !$record->is_editable),