URP stands for user role permissions. A basic package for kickstarting laravel project that contain multiple user roles and permission.
- Publishable role and permission migrations
- Create user
roles
andpermissions
using artisan command line - Assign
roles
andpermissions
to user from artisan command - Role & Permission middleware
- Check
$user->hasPermissionTo
- Check
$user->hasRole
- Blade
@can
,@cannot
directive
URP requires Laravel 5.3+ to run.
Install using composer
on fresh laravel project.
composer require agoussec/urp
Add HasPermission trait in User Model.
<?php
namespace App\Models;
...
...
use Agoussec\URP\Traits\HasPermissions;
class User extends Authenticatable
{
use HasPermissions;
...
...
}
Creating User role
php artisan role:add {rolename} {slug?}
Listing all added user roles
php artisan role:list
Assign role to user
php artisan assign:role {roleslug} {usermail}
Create permission
php artisan permission:add {permissionname} {slug?}
Listing all added permissions
php artisan permission:list
Migration file will atoumatically load after installation of package. just need to run migrate
cammand.
php artisan migrate
RoleMiddleware
// In Route
Route::get('test/middleware', [TestController::class, 'testShow'])->name('test.role')->middleware('role:role1|role2,permission');
can
if($request->user()->can('create-tasks')) {
//Code goes here
}
role
$user->hasRole('developer')
permission
$user->givePermissionsTo('create-tasks')
Role
@role('developer')
Hello developer
@endrole
can
@can('add-course')
<li class="nav-item"><a href="{{ route('admin.course.add') }}" class="nav-link">Add New Course</a></li>
@endcan
@canany(['view-course', 'edit-course', 'delete-course'])
<li class="nav-item "><a href="{{ route('admin.course.manage') }}" class="nav-link">Manage Courses</a></li>
@endcanany
- Console commands for removing
roles
,permissions
- Commands for giving
permission
to specific user or userrole
- Policies logic around a particular model or resource.
- Test cases
MIT
Free Software, Hell Yeah!