Skip to content

Set up permissions for spatie/laravel-permission

License

Notifications You must be signed in to change notification settings

rickselby/laravel-permission-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Initialise Permissions

When using spatie/laravel-permission I have a pattern I always follow; I only use permissions in the code, not roles. Since the permissions will be hard-coded, I want a way of creating the permissions in the database from a list.

This really, really simple class loads a list of permissions from config/permissions.php and creates them (if they don't already exist).

Install the package using composer:

$ composer require rickselby/laravel-permission-setup

Then, if using Laravel 5.4, add the service provider to the providers array:

// config/app.php
'providers' => [
    ...
    RickSelby\Permission\PermissionServiceProvider::class,
];

You can publish the default permissions config file with

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

Now, you can load and reload the list of permissions with the artisan command:

php artisan permission:update