@lacoder role has permissions relationship, so, just eager load it
$role = Role::where('roles.id', $role_id)
->with('permissions')
->get();
and the you can access it as
$role->permissions
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I am using Laravel Permissions from https://spatie.be/docs/laravel-permission/v4/basic-usage/basic-usage
I have created roles and permissions, but now I am editing the role which was created. So now I need to pull all permissions which are assigned to a role,
$role = Role::where('roles.id', $role_id)
->leftjoin('role_has_permissions', 'role_has_permissions.role_id', '=', 'roles.id')
->leftjoin('permissions', 'permissions.id', '=', 'role_has_permissions.permission_id')
->select('permissions.*', 'roles.*')
->get();
But i can not get 3rd table data of permissions, what i want is, role details + all permissions to that role.
Thanks,
Please or to participate in this conversation.