Reputation: 190
I have one problem. I created permission using spaite and composer require command. In migrations directory there is create_permission file exist. So, i migrated but table not created. i discovered this error when i rollback migration using php artisan migrate:rollback or php artisan migrate:reset. what is the problem? i used laravel 8 And other laravel 8 project create table but now current project is same laravel 8 but not create table and has error when rollback. also, i can see to be created personal_access_token table in current project. what is reason? Please help me.
Upvotes: 1
Views: 2087
Reputation: 2844
Did you follow the following steps when installing this composer package(spatie or laravel-permission) to laravel:
Install composer package(laravel-permission or spatie) to Laravel:
composer require spatie/laravel-permission
config/app.php
'providers' => [
....
Spatie\Permission\PermissionServiceProvider::class,
],
We can also custom changes on Spatie package, so if you also want to changes then you can fire bellow command and get config file in config/permission.php and migration files.
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
Now you can see permission.php file and one migrations. so you can run migration using following command:
php artisan migrate
Spatie package provide it's in-built middleware that way we can use it simply and that is display as bellow: So, we have to add middleware in Kernel.php file this way : app/Http/Kernel.php
....
protected $routeMiddleware = [
....
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class,
]
....
Upvotes: 1