Looking to hire Laravel developers? Try LaraJobs

rolespermissions maintained by laravelroles

Description
Roles and Permissions for Laravel Project
Last update
2025/12/19 14:49 (dev-master)
Links
Downloads
44

Comments
comments powered by Disqus

Fine-grained Access Control Package

Technologies

  • Laravel
  • Tailwind

Installation

  1. In the terminal:
	composer require laravelroles/rolespermissions
  1. Register service provider in file /bootstrap/providers.php
return [
    ...
    Laravelroles\Rolespermissions\RolespermissionsServiceProvider::class,
];
  1. Register package middleware in bootstrap/app.php
->withMiddleware(function (Middleware $middleware): void {
        $middleware->alias([
            'bindings' => SubstituteBindings::class,
            'permissions.required' => PermissionsRequiredMiddleware::class
        ]);
    })
  1. In terminal:
	php artisan vendor:publish --provider="Laravelroles\Rolespermissions\RolespermissionsServiceProvider"
  1. In terminal:
	php artisan migrate
  1. In terminal:
	composer dump-autoload
  1. In terminal:
	php artisan laravelroles:seeder
  1. Class App\Models\User extends Laravelroles\Rolespermissions\Models\User

	use Laravelroles\Rolespermissions\Models\User as BaseUser;


	class User extends BaseUser

	{


	}
  1. Set localization in config/app.php - bg or en

  2. Log in main program with example user test@test.bg and password test

Middleware

Add attribute to the middleware name

Route::resource('salaries', 'SalaryController')->middleware('permissions.required:user_id');

Interfaces

  • Users

Image Image Image Image Image

  • Roles

Image Image Image Image

  • Permissions

Image Image Image Image

Blade directives

  • path($permissionName) - Filters records by condition if the subject (the current user who interacts with the system) is authorized to access the permission $permissionName Example:
@path('posts.edit')
	...
@endpath
  • owns($attributeValue) - Filters records by condition if the subject's id is equal to $attributeValue Example:
@owns($attributeValue)
	...
@endowns
  • has($attributeValue, $permissionName) - Filters records by condition if the subject's id is equal to $attributeValue OR the user is authorized to access the permission $permissionName

Example:

@has($posts->author_id, 'posts.edit')
	...
@endhas