Package Data | |
---|---|
Maintainer Username: | kilroyweb |
Package Create Date: | 2017-01-15 |
Package Last Update: | 2017-10-05 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-26 15:12:45 |
Package Statistics | |
---|---|
Total Downloads: | 24 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 1 |
Total Open Issues: | 0 |
Class-based authorization for Laravel
Add to providers:
KilroyWeb\Permissions\Providers\PermissionServiceProvider::class,
publish config:
php artisan vendor:publish --tag=config
php artisan make:permission CLASSNAME
ie:
php artisan make:permission ManageUsers
Create a new migration:
Schema::create('role_permissions', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('permission');
$table->timestamps();
});
and model:
php artisan make:model RolePermission
Create a new migration:
Schema::create('user_permissions', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('permission');
$table->timestamps();
});
and model:
php artisan make:model UserPermission
Add the HasPermissions trait to your User/Role model:
use \KilroyWeb\Permissions\Traits\HasPermissions;
Along with a pointer to the permission model:
protected $permissionsClass = \App\UserPermission::class;
The trait provides a few useful properties + methods:
$user->permissionClassNames
uses Laravel's hasmany to return the direct linked permission classes
$user->permissions
Returns a collection of permission class instances
Methods for adding/deleting permissions:
$user->addPermission($permissionInstance); $user->deletePermission($permissionInstance); $user->syncPermissions($permissionInstances);