Download the PHP package authority-php/authority-laravel without Composer
On this page you can find all versions of the php package authority-php/authority-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download authority-php/authority-laravel
More information about authority-php/authority-laravel
Files in authority-php/authority-laravel
Package authority-laravel
Short Description A simple and flexible authorization system for PHP
License MIT
Homepage https://github.com/authority-php/authority-laravel
Informations about the package authority-laravel
Authority-Laravel
A simple and flexible authorization system for Laravel 5
Installation via Composer
Add Authority to your composer.json file to require Authority
require : {
"laravel/framework": "~5.0.16",
"authority-php/authority-laravel": "dev-master"
}
Now update Composer
composer update
The last required step is to add the service provider to config/app.php
Congratulations, you have successfully installed Authority. However, we have also included some other configuration options for your convenience.
For Laravel 4 supports, see Authority-Laravel 2.3 branch
Additional (optional) Configuration Options
Add the alias (facade) to your Laravel app config file.
This will allow you to access the Authority class through the static interface you are used to with Laravel components.
Publish the Authority default configuration file
This will place a copy of the configuration file at config/authority.php
. The config file includes an 'initialize' function, which is a great place to setup your rules and aliases.
Create Roles and Permissions Tables
We have provided a basic table structure to get you started in creating your roles and permissions.
Publish them to your migrations directory or copy them directly.
Run the migrations
This will create the following tables
- roles
- role_user
- permissions
To utilize these tables, you can add the following methods to your User
model. You will also need to create Role and Permission Model stubs.
Lastly, in your Authority config file which you copied over in the previous configuration step. You can add some rules:
General Usage
Interface
There are 5 basic functions that you need to be aware of to utilize Authority.
-
allow: create a rule that will allow access a resource
example 1:
example 2, using an extra condition:
-
deny: create a rule that will deny access a resource
example 1:
example 2, using an extra condition:
-
can: check if a user can access a resource
example:
-
cannot: check if a use cannot access a resource
example:
-
addAlias: alias together a group of actions
this example aliases together the CRUD methods under a name of
manage
Converting to this library, where you previously had been using the IoC container to resolve an instance.
The service provider will merely create a new instance of Authority, and pass in the currently logged in user to the constructor. This should be basically the same process that you were doing in your IoC registry. This means that any code you have used in the past should still work just fine! However it is recommended that you move your rule definitions into the provided configuration file.
All versions of authority-laravel with dependencies
illuminate/support Version 5.0.x|5.1.x|5.2.x|5.3.x|5.4.x
authority-php/authority Version ~2.2.2