/** * Get collection of users by the specified role. * * @param string $role * @return \Illuminate\Support\Collection */ public function getAllByRole($role = null) { $users = User::where('role', '=', $role)->get(); if ($users->count()) { $users = $users->keyBy('id'); $ids = array_keys($users->all()); $accounts = $this->getBatchedCollection($ids); foreach ($accounts as $account) { $account = $this->appendRole($account, $users[$account->id]->role); } return collect($accounts); } return $users; }