public function transportSummary($confId, Request $req) { if (!Entrust::can(PermissionNames::ConferenceTransportationEdit($confId))) { return response()->json(['message' => 'cannot_manage_transport'], 403); } if (!$this->isValidConference($confId)) { return response()->json(['message' => 'conference_not_found'], 404); } $userConfs = UserConference::where('needsTransportation', '=', true)->where('conferenceID', $confId)->where('approved', 1)->with(array('user' => function ($q) { $q->select('id', 'firstName', 'lastName', 'accountID'); }))->with('userTransportation'); $transports = []; foreach ($userConfs->get() as &$userConf) { $ut = $userConf->userTransportation; if ($ut != null) { $transport = Transportation::where('id', $ut->transportationID)->first(); $transports[$transport->id] = $transport; } } $flightsList = $userConfs->distinct()->lists('flightID'); $flights = Flight::whereIn('id', $flightsList)->get()->keyBy('id')->toArray(); $conference = Conference::where('id', $confId)->get()->toArray(); $summary = $this->buildSummaryJson($conference, $flights, $userConfs->get()->toArray(), $transports); return response()->json($summary, 200); }