public function showRecipeDetail($recipeId) { $theRecipe = Recipes::find($recipeId); $plantRecipe = new PlantRecipe(); $plantsForRecipe = $plantRecipe->findPlantsForRecipe($recipeId); $data = array('recipe' => $theRecipe, 'plants' => $plantsForRecipe); return View::make('recipeDetailView')->with('data', $data); }
/** * Finds all the plant associated with the given recipe * @param $recipeId * @return array */ public function findPlantsForRecipe($recipeId) { $plants = PlantRecipe::where('recipe_id', '=', $recipeId)->get(); $plantArray = array(); foreach ($plants as $plant) { $plantArray[] = Plants::where('id', '=', $plant['plant_id'])->get()[0]; } return $plantArray; }