public function getSpeciesByID(Request $request) { $spID = $request->input('spID'); $speciesObject = Species::where('spID', '=', $spID)->where('uploadToWeb', '=', 1)->get(); $speciesObject[0]->images->toArray(); $speciesObject[0]->bioNotes->toArray(); $speciesObject[0]->synonyms->toArray(); $speciesObject[0]->litSources->toArray(); $speciesObject[0]->interactions->toArray(); $hierachy = []; $parentTaxaGroupID = $speciesObject[0]->taxaGroupID; while (TaxaGroup::find($parentTaxaGroupID)->tier > 1) { $taxaGroupName = TaxaGroup::find($parentTaxaGroupID)->TaxaGroupName; array_unshift($hierachy, ['taxaGroupID' => $parentTaxaGroupID, 'TaxaGroupName' => $taxaGroupName]); $parentTaxaGroupID = TaxaGroup::find($parentTaxaGroupID)->parentTaxaGroupID; } return response()->json(['speciesObject' => $speciesObject, 'hierachy' => $hierachy]); }