Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s00d/permissions
Laravel 5 package for handling user roles and permissions
https://github.com/s00d/permissions
Last synced: about 1 month ago
JSON representation
Laravel 5 package for handling user roles and permissions
- Host: GitHub
- URL: https://github.com/s00d/permissions
- Owner: s00d
- Created: 2015-12-04T07:25:47.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-04T09:03:41.000Z (about 9 years ago)
- Last Synced: 2023-07-15T21:13:56.702Z (over 1 year ago)
- Language: PHP
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Permissions
===========Tiny Laravel 5 package for handling user roles and permissions.
Installation
============Add the following to the require key of your composer.json file:
"s00d/permissions": "dev-master"
Run `$ composer update`.Navigate to your `config/app.php` file and add `'s00d\Permissions\PermissionsServiceProvider'` to the `$providers` array.
Create the tables by running `$ php artisan migrate package="s00d/permissions"`. Ensure that your `users` table exists first.
Navigate to your `models/User.php` file and add the `s00d\Permissions\Can` trait below the class decloration line:
class User extends Eloquent implements UserInterface, RemindableInterface {
use s00d\Permissions\Can;
Usage
=====Create a new role:
$role = new \s00d\Permissions\Role();
$role->name = 'Administrator';
$role->save();
Create a new permission:$permission = new \s00d\Permissions\Permission();
$permission->name = 'read_articles';
$permission->display_name ='Can read articles';
$permission->save();
Attach the permission to the role:
$role->allow($permission);
Create a user:$user = new User;
$user->role_id = 1;
$user->save();
And you're set! To check if a user has a permission:$user = User::find(1);
if ($user->can('read_articles'))
echo 'The user with the ID of "1" can read articles';
To check if the current authenticated user has a permission:if (Auth::user()->can('read_articles'))
echo 'The current authenticated user can read articles';