$users = DB::table('users') ->when($role, function ($query, $role) { $query->where('role_id', $role); }) ->get();