Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel Policy to limit Filament Bulk Delete

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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 Filament\Tables\Actions\BulkAction) that does iterate through all the items.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading