Package Data | |
---|---|
Maintainer Username: | msamec |
Maintainer Contact: | marko.samec@am2studio.hr (Marko Šamec) |
Package Create Date: | 2016-01-26 |
Package Last Update: | 2016-01-26 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:23:35 |
Package Statistics | |
---|---|
Total Downloads: | 1,564 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 4 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Via Composer
$ composer require am2studio/laravel-acl
in config/app.php
under 'providers'
add
AM2Studio\LaravelAcl\LaravelAclServiceProvider::class
php artisan vendor:publish --provider="AM2Studio\LaravelACL\LaravelACLServiceProvider" --tag=config
php artisan vendor:publish --provider="AM2Studio\LaravelACL\LaravelACLServiceProvider" --tag=migrations
In user model add following
...
use AM2Studio\LaravelAcl\Traits\LaravelACLTrait;
class User extends Model {
use LaravelACLTrait, ... ;
}
use AM2Studio\LaravelACL\Models\Role;
$userRole = Role::create([
'name' => 'User',
'slug' => 'user',
'description => '',
]);
$user = User::find(1);
$user->attachRole($userRole);
$user->detachRole($userRole);
$user->detachAllRoles();
$user->is('user'); // Checkes if user has user role
$user->is('admin|user'); // Checks if user has user OR admin role
$user->is('admin|user', true); // Checks if user has user AND admin role
use AM2Studio\LaravelACL\Models\Permssion;
$p = Role::create([
'name' => 'Event edit',
'slug' => 'event.edit',
'description => '',
]);
$user = User::find(1);
$user->attachPermission($p);
$user->detachPermission($p);
$user->detachAllPermissions();
$role = Role::find(1);
$role->attachPermission($p);
$role->detachPermission($p);
$role->detachAllPermissions();
$user->can('event.edit'); // Checkes if user has permission
$user->can('event.edit|event.create'); // Checks if user has event.edit OR event.create permission
$user->can('event.edit|event.create', true); // Checks if user has event.edit AND event.create permission
$p2 = Role::create([
'name' => 'Event edit',
'slug' => 'event.edit',
'description => '',
'model' => 'event',
]);
$p3 = Role::create([
'name' => 'Event edit',
'slug' => 'event.edit',
'description => '',
'model' => 'event',
'resource_id' => 1,
]);
$event = Event::find(1);
$user->attachPermisson($p2);
$user->attachPermisson($p3);
$user->allowed('event.edit', $event); // Checks if user has rights to Event model
$user->allowed('event.edit', $event, $event->id); // Checks if user has rights to Event model with selected id
@role('admin')
@endrole
@permission('edit.event')
@endpermission
@allowed('edit.event', $event)
@endallowed
@role('admin|user', 'all')
@endrole
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING and CONDUCT for details.
The MIT License (MIT). Please see License File for more information.