Download the PHP package crabbly/authorize without Composer
On this page you can find all versions of the php package crabbly/authorize. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package authorize
Authorize
Authorize is a package for Laravel that provides User Access Control using Roles and Permissions.
Installation
Step 1: Composer
From the command line, run:
Step 2: Service Provider
For your Laravel app, open config/app.php
and, within the providers
array, append:
This will bootstrap the package into Laravel.
Step 3: Publish and Run Migrations
php artisan vendor:publish --provider="Crabbly\Authorize\AuthorizeServiceProvider" --tag="migrations"
php artisan migrate
Step 4: Add the UserAuthorizeTrait
to your User
model:
Basics
Tables
After the migration, four new tables will be present:
roles
— stores role recordsrole_user
— stores many-to-many relations between roles and userspermissions
— stores permission recordspermission_role
— stores many-to-many relations between roles and permissions
Models
The package comes with two models, Role
and Permission
.
Role
The Role
model has three main attributes:
name
— Unique name for the Role, used for looking up role information in the application layer. For example: "admin", "owner", "employee".display_name
— Human readable name for the Role. For example: "User Administrator", "Project Owner", "Company Employee".description
— A more detailed explanation of what the Role does. This field is optional and nullable in the database.
Permission
The Permission
model has the same three attributes as the Role
:
name
— Unique name for the permission, used for looking up permission information in the application layer. For example: "create-post", "edit-user".display_name
— Human readable name for the permission. Not necessarily unique. For example "Create Posts", "Edit Users".description
— A more detailed explanation of the Permission.
Usage
Creating Roles
Create an admin
role:
Assigning and Removing Roles
Roles and Users have a Many to Many relationship. We can attach and detach roles to users like this:
Checking if User has a Role
To check if a User is assigned with the Role admin
:
Most apps will probably have an admin
Role, for this we can just use:
Creating Permissions
Create an delete_users
permission:
Assigning and Removing Permissions
Permissions and Roles have a Many to Many relationship. We can attach and detach permissions to roles like this:
Checking if User has Permission
To check if a User has the Permission delete_users
:
This will check if any of the Roles that were assigned to the user, has the Permission delete_users
.
Contribution
Pull requests are welcome. Please report any issue you find in the issues page.
License
Authorize is free software distributed under the terms of the MIT license.