Level 9
You can use a where in for this
Permissions::whereNotIn('id',$role->permissions->lists('id'));
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello experts,
How do i query permissions that are not aleady assigned in a role. The intermideary table has permission_id, and role_id fields, table name: permission_role. Help much appreciated.
Thank for the suggestion. It works!! Only problem with your submitted code is Permissions, where it should be Permission. Updated code: public function getUnAssignedPermissions($id){ $role = Role::find($id);
$permissions = Permission::whereNotIn('id',$role->permissions->lists('id', 'name'))->get();
return $permissions;
}
Please or to participate in this conversation.