Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shimana's avatar

how to check permissions through roles

I have this tables:

users
permissions
roles
role_user
permission_role

i want check Permissions through roles . i use this function :

    public function hasPermission(Permission $permission)
    {
        return $this->hasRole($permission->roles);
    }

show error

App\Models\User::hasPermission(): Argument #1 ($permission) must be of type App\Models\Permission, string given, called in
0 likes
1 reply
jlrdw's avatar
jlrdw
Best Answer
Level 75

Not sure of all of your structure, but usually it's something like:

$whatever  =  Role::with('permissions')->get();
1 like

Please or to participate in this conversation.