Reputation: 31
i am using the spatie permission package.I want to assign a permission to a role.Below Is my method in controller:
public function testing_role_permission()
{
$role = Role::findById(2);
$permission = Permission::findById(1);
$role->givePermissionTo($permission);
}
It is showing me exception PermissionDoesNotExist
There is no [permission] with id 1
.
Before it the same method was working and permission was assigned to the role.But i create some new permissions in PermissionTableSeeder.After doing this it's not working.I searched a lot trying to clear cache but nothing happen to this Exception.
PermissionTableSeeder.php
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
class PermissionTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
app()[\Spatie\Permission\PermissionRegistrar::class]-
>forgetCachedPermissions();
//role permissions
Permission::create(['name' => 'create_role']);
Permission::create(['name' => 'read_role']);
Permission::create(['name' => 'update_role']);
Permission::create(['name' => 'delete_role']);
Permission::create(['name' => 'disable_role']);
Permission::create(['name' => 'isolation_role']);
}
}
How to Solve this Error?
Thanks in advance!
Upvotes: 2
Views: 5146
Reputation: 2049
In your permission table give check your guard_name. If it is empty or something mismatch then maybe you are getting that error.
Upvotes: 1