laravel-chameleon-access
You can install the package via composer:
composer require spatie/laravel-permission
Optional: The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file:
'providers' => [
// ...
NekoOs\ChameleonAccess\Providers\Initialize::class,
];
You should publish the migration and the config/permission.php config file with:
php artisan vendor:publish --provider="NekoOs\ChameleonAccess\Providers\Initialize"
First, add the NekoOs\ChameleonAccess\HasScopes trait to your User model(s):
use NekoOs\ChameleonAccess\HasScopes;
class User
{
use HasScopes;
// ...
}
A role can be assigned to any user by a scope:
$user->withScopeAssignRoles($model, 'writer');