Subscribe to PHP Freaks RSS

Laravel News: Bouncer: a Laravel Package for Role and Ability Authorization

syndicated from www.phpdeveloper.org on July 18, 2017

On the Laravel News site there's a new post highlighting a package that can help you enforce roles and permissions in your application, enhancing the existing gates functionality.

Bouncer is an authorization package by Joseph Silber which allows role and ability checks at Laravel’s authorization gate. The package is described as follows: "Bouncer provides a mechanism to handle roles and abilities in Laravel’s ACL. With an expressive and fluent syntax, it stays out of your way as much as possible: use it when you want, ignore it when you don’t."

Bouncer makes it trivial to quickly create roles and abilities with a fluent API that creates them automatically.

The post includes some examples of the library in use, creating roles and abilities with its fluent API and the use of a trait to integrate it into other classes. They also include a bit about how the automatic role creation works and using the functionality in middleware. It also talks about how Bouncer intercepts "can" checks for its own evaluations and how to get all of the abilities for the current user.