skip to Main Content

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

2

Answers


  1. If $is_editable is false, the button is disabled by adding the disabled attribute. This makes the button unclickable in the browser.If $is_editable is true, the button remains active, meaning it can be clicked. the same logic applied delete button.

    <button class="btn edit-btn" @if(!$is_editable) disabled @endif >Edit
    <button class="btn delete-btn" @if(!$is_deletable) disabled @endif >Delete

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

    TablesActionsDeleteAction::make()
       ->disabled(fn($record) => !$record->is_deletable),
    TablesActionsEditAction::make()
       ->disabled(fn($record) => !$record->is_editable),
    

    Same is for hidden:

    TablesActionsDeleteAction::make()
       ->hidden(fn($record) => !$record->is_deletable),
    TablesActionsEditAction::make()
       ->hidden(fn($record) => !$record->is_editable),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search