Package Data | |
---|---|
Maintainer Username: | shitoudev |
Maintainer Contact: | marius@updivision.com (Marius Constantin) |
Package Create Date: | 2017-08-05 |
Package Last Update: | 2017-08-05 |
Home Page: | http://backpackforlaravel.com |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-15 15:03:28 |
Package Statistics | |
---|---|
Total Downloads: | 7 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
An admin interface to easily add/edit/remove users, roles and permissions, using Laravel Backpack. As opposed to some other packages:
Security updates and breaking changes
Please subscribe to the Backpack Newsletter so you can find out about any security updates, breaking changes or major features. We send an email every 1-2 months.
$ composer require backpack/permissionmanager
Backpack\PermissionManager\PermissionManagerServiceProvider::class,
$ php artisan vendor:publish --provider="Backpack\PermissionManager\PermissionManagerServiceProvider" #publish config files and migrations
$ php artisan migrate #create the role and permission tables
<?php namespace App;
use Backpack\CRUD\CrudTrait; // <------------------------------- this one
use Spatie\Permission\Traits\HasRoles;// <---------------------- and this one
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use CrudTrait; // <----- this
use HasRoles; // <------ and this
/**
* Your User Model content
*/
<!-- Users, Roles Permissions -->
<li class="treeview">
<a href="#"><i class="fa fa-group"></i> <span>Users, Roles, Permissions</span> <i class="fa fa-angle-left pull-right"></i></a>
<ul class="treeview-menu">
<li><a href="{{ url(config('backpack.base.route_prefix', 'admin') . '/user') }}"><i class="fa fa-user"></i> <span>Users</span></a></li>
<li><a href="{{ url(config('backpack.base.route_prefix', 'admin') . '/role') }}"><i class="fa fa-group"></i> <span>Roles</span></a></li>
<li><a href="{{ url(config('backpack.base.route_prefix', 'admin') . '/permission') }}"><i class="fa fa-key"></i> <span>Permissions</span></a></li>
</ul>
</li>
Because the package requires spatie/laravel-permission, the API will be the same:
A permission can be given to a user:
$user->givePermissionTo('edit articles');
A permission can be revoked from a user:
$user->revokePermissionTo('edit articles');
You can test if a user has a permission:
$user->hasPermissionTo('edit articles');
Saved permissions will be registered with the Illuminate\Auth\Access\Gate-class. So you can test if a user has a permission with Laravel's default can-function.
$user->can('edit articles');
A role can be assigned to a user:
$user->assignRole('writer');
A role can be removed from a user:
$user->removeRole('writer');
You can determine if a user has a certain role:
$user->hasRole('writer');
You can also determine if a user has any of a given list of roles:
$user->hasAnyRole(Role::all());
You can also determine if a user has all of a given list of roles:
$user->hasAllRoles(Role::all());
The assignRole, hasRole, hasAnyRole, hasAllRoles and removeRole-functions can accept a string, a Role-object or an \Illuminate\Support\Collection-object.
A permission can be given to a role:
$role->givePermissionTo('edit articles');
You can determine if a role has a certain permission:
$role->hasPermissionTo('edit articles');
A permission can be revoked from a role:
$role->revokePermissionTo('edit articles');
The givePermissionTo and revokePermissionTo-functions can accept a string or a Permission-object.
Saved permission and roles are also registered with the Illuminate\Auth\Access\Gate-class.
$user->can('edit articles');
This package also adds Blade directives to verify whether the currently logged in user has all or any of a given list of roles.
@role('writer')
I\'m a writer!
@else
I\'m not a writer...
@endrole
@hasrole('writer')
I\'m a writer!
@else
I\'m not a writer...
@endhasrole
@hasanyrole(Role::all())
I have one or more of these roles!
@else
I have none of these roles...
@endhasanyrole
@hasallroles(Role::all())
I have all of these roles!
@else
I don\'t have all of these roles
@endhasallroles
You can use Laravels native @can directive to check if a user has a certain permission.
Please see CHANGELOG for more information what has changed recently.
// TODO
If you need to modify how this works in a project:
routes/backpack/permissionmanager.php
file; the package will see that, and load your routes file, instead of the one in the package;Please see CONTRIBUTING for details.
If you discover any security related issues, please email hello@tabacitu.ro instead of using the issue tracker.
Please subscribe to the Backpack Newsletter so you can find out about any security updates, breaking changes or major features. We send an email every 1-2 months.
Backpack is free for non-commercial use and $19/project for commercial use. Please see License File and backpackforlaravel.com for more information.