In Laravel, roles and permissions have been one of the most confusing topics over the years. Mostly, because there is no documentation about it: the same things “hide” under other terms in the framework, like “gates”, “policies”, “guards”, etc. In this article, I will try to explain them all in “human language”.

Gate is the same as Permission
One of the biggest confusions, in my opinion, is the term “gate”. I think developers would have avoided a lot of confusion if they were called what they are.

Gates are Permissions, just called by another word.

What are the typical actions we need to perform with permissions?

Define the permission, ex. “manage_users”
Check the permission on the front-end, ex. show/hide the button
Check the permission on the back-end, ex. can/can’t update the data
So yeah, replace the word “permission” with “gate”, and you understand it all.

Various Ways to Check Gate Permission
Option 1. Routes: middleware(‘can:xxxxxx’)
Option 2. Controller: can() / cannot()
Option 3. Gate::allows() or Gate::denies()
Option 4. Controller: authorize()
Option 5. Form Request class:

Credits :

Leave a Reply

Your email address will not be published. Required fields are marked *