PHP Classes

Laravel User Role and Permission: Manage the user roles in Laravel applications

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 33 All time: 11,097 This week: 455Up
Version License PHP version Categories
laravel-urp 1.0.0Custom (specified...5PHP 5, User Management, Libraries
Description 

Author

This package can manage the user roles in Laravel applications.

It provides controllers, middleware, models, command classes for use in applications that use the Laravel framework, so you can perform several types operations from the command line using the artisan tool to manage the application user roles and permissions.

Currently it can:

- Add new roles

- List available roles

- Create new permissions

- List available permissions

- Check if a user is assigned to a role

- Check of a user has a permission

- Assign permissions to users

- Provide blade directives to allow controlling the display of certain sections of a template depending other the current user roles or permissions

Picture of shamsh parvez
  Performance   Level  

 

Documentation

URP

A laravel package for kickstarting user role and permission project

URP stands for user role permissions. A basic package for kickstarting laravel project that contain multiple user roles and permission.

Features

  • Publishable role and permission migrations
  • Create user `roles` and `permissions` using artisan command line
  • Assign `roles` and `permissions` to user from artisan command
  • Role & Permission middleware
  • Check `$user->hasPermissionTo`
  • Check `$user->hasRole`
  • Blade `@can`, `@cannot` directive

Installation

URP requires Laravel 5.3+ to run.

Install using composer on fresh laravel project.

composer require agoussec/urp

Usage

Console commands -

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

Migration file will atoumatically load after installation of package. just need to run migrate cammand.

php artisan migrate

Middleware

RoleMiddleware


// In Route
    Route::get('test/middleware', [TestController::class, 'testShow'])->name('test.role')->middleware('role:role1|role2,permission');

Controller


can

if($request->user()->can('create-tasks')) {
    //Code goes here
}

role

$user->hasRole('developer')

permission

$user->givePermissionsTo('create-tasks')

Blade directive

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

TODOs

  • Console commands for removing `roles`, `permissions`
  • Commands for giving `permission` to specific user or user `role`
  • Policies logic around a particular model or resource.
  • Test cases

Credits

License

MIT

Free Software, Hell Yeah!


  Files folder image Files (18)  
File Role Description
Files folder imagesrc (1 file, 5 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:33
This week:0
All time:11,097
This week:455Up