/** * return the questions from the database * * @return array questions */ public function all() { if (!Auth::check()) { return Response::json(['error' => ['message' => 'not authorized, not logged in']]); } else { if (!Auth::user()->isAdmin()) { return Response::json(['error' => ['message' => 'not authorized, elevated permissions needed']]); } } $teamsCount = Team::count(); // get the questions for that page $teams = Team::all(); for ($i = 0; $i < count($teams); $i++) { $teams[$i]['username'] = User::findOrFail($teams[$i]->user_id)->username; } $result = array('teams' => $teams, 'teamsCount' => $teamsCount); // return the result return $result; }