PHP Classes

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

Recommend this page to a friend!
  Info   View files Documentation   View files View files (18)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2021-11-13 (9 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 31 All time: 10,562 This week: 330Up
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  
Name: shamsh parvez <contact>
Classes: 2 packages by
Country: India India
Age: ???
All time rank: 4156289 in India India
Week rank: 606 Up41 in India India Up

Details

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  
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

  Files folder image Files  /  src  
File Role Description
Files folder imageConsole (5 files)
Files folder imagedatabase (1 directory)
Files folder imageMiddleware (1 file)
Files folder imageModels (2 files)
Files folder imageTraits (1 file)
  Plain text file PermissionsServiceProvider.php Class Class source

  Files folder image Files  /  src  /  Console  
File Role Description
  Plain text file AddPermission.php Class Class source
  Plain text file AddRole.php Class Class source
  Plain text file AssignRole.php Class Class source
  Plain text file ListPermissions.php Class Class source
  Plain text file ListRoles.php Class Class source

  Files folder image Files  /  src  /  database  
File Role Description
Files folder imagemigrations (5 files)

  Files folder image Files  /  src  /  database  /  migrations  
File Role Description
  Plain text file 2021_10_21_083951_...ermission_table.php Class Class source
  Plain text file 2021_10_21_084017_create_role_table.php Class Class source
  Plain text file 2021_10_21_084156_...rmissions_table.php Class Class source
  Plain text file 2021_10_21_084247_...ers_roles_table.php Class Class source
  Plain text file 2021_10_21_084333_...rmissions_table.php Class Class source

  Files folder image Files  /  src  /  Middleware  
File Role Description
  Plain text file RoleMiddleware.php Class Class source

  Files folder image Files  /  src  /  Models  
File Role Description
  Plain text file Permission.php Class Class source
  Plain text file Role.php Class Class source

  Files folder image Files  /  src  /  Traits  
File Role Description
  Plain text file HasPermissions.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:31
This week:0
All time:10,562
This week:330Up
For more information send a message to info at phpclasses dot org.