Download the PHP package leoche/laravel-lpermissions without Composer
On this page you can find all versions of the php package leoche/laravel-lpermissions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download leoche/laravel-lpermissions
More information about leoche/laravel-lpermissions
Files in leoche/laravel-lpermissions
Package laravel-lpermissions
Short Description Users Roles & Permissions for routes
License MIT
Informations about the package laravel-lpermissions
Laravel LPermissions adds roles and permissions to Auth Laravel 5.3. Protect your routes and your views.
Table of Contents
- Requirements
- Installation
- Methods Usage
- Routes Usage
- Blades Usage
- Example
- Todo
Requirements
- This package requires PHP 5.5+
- This package requires Laravel 5.3
Installation
1. Require the package in your composer.json
and update your dependency with composer update
:
2. Add the package to your application service providers in config/app.php
.
3. Publish the package migrations to your application and run these with php artisan migrate
.
4. Add the middleware to your app/Http/Kernel.php
.
5. Add the HasRole trait to your User
model.
Methods Usage
Roles
Creating roles
Assign or Remove a role
Assign or remove an inherit role to a role
Assign or remove a permission to a role or a user
Notes : LPermissions parse permissions path as:
Given Path | Parsed path |
---|---|
home/ | home |
/blog/:slug | blog/:slug |
blog/:alpha/ | blog/:alpha |
/blog/:number/comments/ | blog/:number/comments |
Given keys | Regex |
---|---|
* |
(.*?) |
:number |
(\d*?) |
:alpha |
([A-z]*?) |
:alphanum |
([A-z0-9]*?) |
:slug |
([A-z0-9-_]*?) |
Routes Usage
You just have to specifythe middleware to the group route. It will check for permission and abort 401 if unauthorised
Blades Usage
In your blades view you can use directives to show something (eg: links, infos) only if the user has the permission or the role
Example
Users Table
id | username | role_id |
---|---|---|
1 | Mike | 0 |
2 | Lisa | 1 |
3 | John | 2 |
Roles Table
id | inherit_id | name |
---|---|---|
1 | 1 | Admin |
2 | 0 | Member |
Permissions Table
id | route | method | user_id | role_id |
---|---|---|---|---|
1 | /admin/* | * | 0 | 1 |
2 | /account/* | GET | 0 | 2 |
3 | /secret | GET | 1 | 0 |
Route web.php
Everyone can see the homepage
Only mike can view /secret
Lisa can do anything in /admin/* and view account pages (inherit from members)
John can only view accounts pages
Todo
- [x] Function to assign/revoke role to users
- [x] Function to assign/revoke permission to role
- [x] Function to inherit role to role