spatie 权限 对于守卫“web”,没有名为“create”的权限。拉拉维尔

问题描述 投票:0回答:1

我正在使用 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);
}
laravel permissions
1个回答
0
投票
 $permissions = $request->input('permission');

        $permissions = array_map(function ($item) {
          return (int)$item;
        }, $permissions);
           
        if (!empty($permissions)){
          $role->syncPermissions($permissions);
        }
© www.soinside.com 2019 - 2024. All rights reserved.