skip to Main Content

In my Laravel project, I try to limit delete action. Non-admin users should be able to delete only their own content.

public function forceDelete(User $user, Slider $slider): bool
{
    return $user->hasRole("Admin") || $slider->created_by === $user->id;
}

I can still see the bulk delete action select and I can still delete the content I didn’t create.

Is there a solution for this problem?

2

Answers


  1. Unfortunately, all the built-in bulk actions suffer from this issue.

    https://filamentphp.com/docs/3.x/panels/resources/getting-started#authorization

    Filament uses the forceDeleteAny() method because iterating through multiple records and checking the forceDelete() policy is not very performant.

    In our case, we made a custom action (extended off FilamentTablesActionsBulkAction) that does iterate through all the items.

    Login or Signup to reply.
  2. Does anyone know what about redirecting after checking the Policy?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search