Laravel: On-demand authorization

Quick and not dirty

Let’s say we have a controller where the user can publish an Article. The Article itself must meet only one condition to be published: it has to be approved by an editor beforehand, something that is done elsewhere in the application.

Making authorization relatable

The above code makes sense for the developer, but not for the end user.

Do it simple, or do it complex

There are few scenarios where you will want to make a check over the authenticated user. You don’t need to register an action into the Gate, but instead, you can pass a callback that receives an user instance.

Graphic Designer graduate. Full Stack Web Developer. Retired Tech & Gaming Editor.