aircraftRepo = $aircraftRepo; $this->subfleetRepo = $subfleetRepo; } /** * Return all the subfleets and the aircraft and any other associated data * Paginated */ public function index() { $subfleets = $this->subfleetRepo ->with(['aircraft', 'airline', 'fares', 'ranks']) ->paginate(); return SubfleetResource::collection($subfleets); } /** * Get a specific aircraft. Query string required to specify the tail * /api/aircraft/XYZ?type=registration * @param $id * @param Request $request * @return AircraftResource */ public function get_aircraft($id, Request $request) { $where = []; if ($request->filled('type')) { $where[$request->get('type')] = $id; } else { $where['id'] = $id; } $aircraft = $this->aircraftRepo ->with(['subfleet', 'subfleet.fares']) ->findWhere($where) ->first(); return new AircraftResource($aircraft); } }