##Guardian: Role Based Access Control Package For Laravel 5 and 4 With Backend Interface
###For Laravel 4 please switch to the old branch .
Guardian package for Laravel provides an easy interface to manage Role Based Access Control. Through its minimalist interface you can add users, roles and capabilities. Each user can be assigned multiple roles (many to many) and each role can be assigned multiple capabilities.
Guardian also comes with plenty of Access Control helper methods that make it easy to track access for a specific user inside your code.
##Installation and Setup
To install guardian, add the following lines in your composer.json file:
After adding the above lines, save the file and run:
composer update --dev
After the successful completion of the composer installation process, add the following line to the providers array inside the app/config/app.php file:
If you have not already installed the illuminate/html package, then you will need to add the Illuminate\Html\HtmlServiceProvider into the providers array as well.
###Running Package Migrations
To setup the database for the guardian, you will need to run the following commands to run the package migration files:
Please note that, if your models are namespaced other then App\, you will need to reflect the changes in the package config.php file. You can use the following command to copy the package configuration file into your app/config directory:
After making the requested changes you will be able to access the guardian backend at http://www.yoursite.com/guardian/backend. The auth middleware is applied by default. So, you will need to log in first.
In a development/local environment you can remove the 'middleware'=>'auth' key value pair from the package's routes.php file for a test drive.
The following helper methods are available through Guardian Facade:
Guardian::hasRole($roleName) - returns true if the current user has the role otherwise false will be returned.
Guardian::hasAnyRole(array $roleNames) - returns true if user has any of the supplied roles otherwise false will be returned.
Guardian::hasAllRoles(array $rolesNames) - returns true only if user has all the supplied roles otherwise false will be returned.
Guardian::hasCapability($capabilityName) - returns true if the user has the supplied capability otherwise false will be returned.
Guardian::hasAnyCapability($capabilityNames) - returns true if the user has any of the supplied capabilities otherwise false will be returned.
Guardian::hasAllCapabilities($capabilityNames) - returns true if the user has all the supplied capabilities otherwise false will be returned.