pluck('department_id')->toArray(); $roles = PermissionRole::where('permission_ids', 'LIKE', '%"'.$pid.'"%')->pluck('role_id')->toArray(); $u = User::whereIn('department_id', $deps)->whereHas('role_user', function($q) use($roles){ $q->whereIn('role_id', $roles); })->get(['id', 'first_name', 'last_name']); return $u; } }