Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

reviewdevs's avatar

How to handle authorization if you have many to many based roles and permissions

I wanted to make roles and permissions to be as dynamic as possible, here is what I made on Diagram.io

https://drive.google.com/file/d/1NNyFpZZLiIhQwFgVnX26dgm-v7Ar8Th_/view?usp=sharing

however I was wondering how would I handle if user is authorized to do some action in Laravel

0 likes
1 reply
automica's avatar
automica
Best Answer
Level 54

@reviewdevs depending on what package you are using for permissions, you can do a check for the role or permission at the top of your controller method and also add the appropriate check in your blade.

using spatie/permissions

in controller:

// for roles
$user->hasRole('writer');

// for permissions
$user->can('edit articles');

and in blade:

@can('edit articles')
...
@endcan

see https://spatie.be/docs/laravel-permission/v3/introduction

Please or to participate in this conversation.