Package Data | |
---|---|
Maintainer Username: | hamedmehryar |
Maintainer Contact: | hamed@netlinks.af (Hamed Mehryar) |
Package Create Date: | 2016-02-04 |
Package Last Update: | 2017-12-02 |
Language: | JavaScript |
License: | MIT |
Last Refreshed: | 2024-12-22 03:10:31 |
Package Statistics | |
---|---|
Total Downloads: | 643 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 3 |
Total Forks: | 1 |
Total Open Issues: | 0 |
Resource-Based permission system for laravel
In composer.json:
"require": {
"hamedmehryar/laracancan" "1.0.0"
}
Run:
composer update
Add the service provider to config/app.php
under providers
:
'providers' => [
Hamedmehryar\Laracancan\LaracancanServiceProvider::class,
]
Create the Migration file:
php artisan laracancan:migration
Migrate your database:
php artisan migrate
Seed the Permissions:
php artisan laracancan:seed
Add the trait to your user model:
use Hamedmehryar\Laracancan\Traits\LaracancanUserTriat;
class User extends Model {
use LaracancanUserTrait;
}
##usage
Permission checking:
Laracancan::canCreate('<resource-name>');
Laracancan::canRead('<resource-name>');
Laracancan::canUpdate('<resource-name>');
Laracancan::canDelete('<resource-name>');
Laracancan::can('<permission-name>', '<resource-name>');
$user->canCreate('<resource-name>');
$user->canRead('<resource-name>');
$user->canUpdate('<resource-name>');
$user->canDelete('<resource-name>');
$user->can('<permission-name>', '<resource-name>');
Role checking:
Laracancan::roles();
Laracancan::hasRole();
$user->roles();
$user->hasRole();
Getting Resources based on Permission:
Laracancan::creatableResources();
Laracancan::readableResources();
Laracancan::updatableResources();
Laracancan::deletableResources();
Laracancan::resourcesByPermission('<permission-name');
$user->creatableResources();
$user->readableResources();
$user->updatableResources();
$user->deletableResources();
$user->resourcesByPermission('<permission-name');
Attaching Roles to user:
$user->attachRole('<role-object>');
$user->detachRole('<role-object>');
$user->attachRoles('<roles>');
$user->detachRoles('<roles>');