我正在为我的 laravel 项目编写一个 ACl 系统,我正在为它使用 gates。 当我尝试使用大门时,我看到了这个错误:
调用 bool 上的成员函数 getKey()
有人能帮我吗?
这是我在 AuthServiceProvider.php 中的代码:
public function boot(): void
{
$this->registerPolicies();
foreach ($this->getPermissions() as $permission) {
Gate::define($permission->name , function ($user) use($permission){
return $user->hasRole($permission->roles);
});
}
}
这是 getPermissions() 函数:
protected function getPermissions(): \Illuminate\Database\Eloquent\Collection|array
{
return Permission::with('roles')->get()->all();
}
这就是我使用盖茨的方式:
public function index(): \\Illuminate\\Contracts\\Foundation\\Application|\\Illuminate\\Contracts\\View\\Factory|\\Illuminate\\Contracts\\View\\View
{
$this->authorize('show-users');
$users = User::latest()->paginate(25);
return view('Admin.users.all' , compact('users'));
}
我的数据库中有这个显示用户权限