Call to a member function getKey() on bool

438 Views Asked by At

i'm writing an ACl system for my laravel project and I'm using gates for it. while I'm trying to use the gates, I see this error:

Call to a member function getKey() on bool

can anyone help me with this?

this is my code in 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);
        });
    }
}

this is getPermissions() function:

protected function getPermissions(): \Illuminate\Database\Eloquent\Collection|array
{    
    return Permission::with('roles')->get()->all();
}

and this is how I used Gates:

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'));
}

and I have this show-users permission in my database

0

There are 0 best solutions below