Laravel Pacgage created by Spatie.

This package allows you to manage user permissions and roles in a database.

Roles and permissions form an important part of many web applications. Laravel historically had a lot of packages for them, and improved the core code as well. SpatieRoles & Permission is one of there best permissions package.

Advantages

  1. Roles
  2. Permissions
  3. Direct Permissions
  4. Middleware
  5. Multiple Blade Directives
  6. Artisan commands

Installation via composer

composer require spatie/laravel-permission
 

The service provider will automatically get registered. Or you may manually add the service provider in your config/app.phpfile:

'providers' => [
    // ...
    Spatie\Permission\PermissionServiceProvider::class,
];

You can publish the migration with:

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"

After the migration has been published you can create the role- and permission-tables by running the migrations:

php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="config"

Usage:

use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;

    // ...
}

Leave a Reply

Your email address will not be published. Required fields are marked *