我正在使用 spatie 权限,但它返回错误
There is no permission named `create` for guard `web`.
我不知道为什么请帮忙 我的代码我在做什么是创建一个新用户然后创建权限然后让用户讲师拥有我创建的权限,所有这些都在播种器中
这是我的代码播种器
public function run()
{
$user = User::create([
'name' => 'admin',
'email' => '[email protected]',
'email_verified_at' => now(),
'password' => 'password', // password
'remember_token' => Str::random(10),
'type' => User::TYPE_INSTRUCTOR,
]);
$permissions =
[
[
'name' => 'methods_create',
'display_name' => 'create',
'key' => 'methods',
],
[
'name' => 'methods_update',
'display_name' => 'update',
'key' => 'methods',
],
[
'name' => 'methods_delete',
'display_name' => 'delete',
'key' => 'methods',
],
];
$role = Role::create(['name'=>'Instructor']);
foreach($permissions as $permission){
Permission::create($permission);
}
$role->givePermissionTo($permissions);
$user->assignRole($role);
}
$permissions = $request->input('permission');
$permissions = array_map(function ($item) {
return (int)$item;
}, $permissions);
if (!empty($permissions)){
$role->syncPermissions($permissions);
}