Download the PHP package mnshankar/role-based-authority without Composer
On this page you can find all versions of the php package mnshankar/role-based-authority. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mnshankar/role-based-authority
More information about mnshankar/role-based-authority
Files in mnshankar/role-based-authority
Package role-based-authority
Short Description Modifies Authority-L4 to use Roles (instead of users) as the central unit of previlege management
License
Informations about the package role-based-authority
Laravel4 - RoleBasedAuthority
This is a simple package that provides role-based access control (RBAC) for Laravel4 applications.
It is very similar to Authority-L4 in that it provides a Laravel 4 shell around the "Authority" package. This package however focuses on managing permissions assigned to "roles" rather than "users".
After examining a whole host of authorization systems for Laravel, I finally settled on Authority
- Easy to understand and manage
- No other external dependencies
- Runs on PHP 5.3+
- Works exactly as advertised
(As far as authentication is concerned, I believe the stock laravel implementation works perfectly)
To install RoleBasedAuthority via composer:
Run composer update to bring in the dependencies.
Add to Provider list (app.php):
Add to Alias list (app.php):
Run all migrations (Remember to setup your database config prior to doing this. Note that it contains a migration for the users table, and as such you might want to inspect the code prior to running):
Publish the configuration file:
(this central config file is where you would put all your rules. In order to cache the "Authority" object, set 'cache' to true and specify cache_ttl)
Create/Modify your User, Role and Permission models to permit relationships (many-to-many between users and roles, one-to-many between roles and permissions): User.php
Role.php
Permission.php
The major changes from Authority are:
- DB migrations (include relationships between users,roles and permissions)
- The "type" field in table "permissions" is set to enum (allow/deny)
- Support for role inheritance (using the "inherited_roleid" column in Roles)
- Config file changes (to loop through all user roles, and create rule list)
- Support for caching the Authority object (set 'cache' to true in config file)
Common usage pattern:
Once you have the tables setup (with users, roles and permissions), checking authorization within your application is fairly trivial. Here is some seed data to get you started:
The following snippets of code demonstrate methods of checking for appropriate privileges:
Adding a role-check can be accomplished using filters like so:
('admin' can then be used as a before filter)
For more instructions on usage and available options, please follow the writeup on authority-l4 (and authority)