public function searchFreezer() { $freezer = Freezers::where('id_user', '=', Auth::user()->id)->get(); foreach ($freezer as $f) { $array_name[] = Ingredients::where('id_ingredient', '=', $f->id_ingredient)->first()->name; } $array = $this->populateSearchView($array_name); return view('search')->with($array); }
private function populateArray() { $ingredients = array(); if (Auth::check()) { $freezer = Freezers::where('id_user', '=', Auth::user()->id)->get(); foreach ($freezer as $f) { $ingredients[$f->id_ingredient] = Ingredients::where('id_ingredient', '=', $f->id_ingredient)->first()->name; } } $all_ingredient = Ingredients::all(); $array['ingredient'] = $ingredients; $array['all_ingredient'] = $all_ingredient; return $array; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index($recipe_id) { $recipe = Recipes::where('id_recipe', '=', $recipe_id)->first(); $recipe_ingredient = Recipes_ingredients::where('id_recipe', '=', $recipe_id)->get(); foreach ($recipe_ingredient as $ri) { $ingredient[] = Ingredients::where('id_ingredient', '=', $ri->id_ingredient)->first(); } $rating = 0; if (Auth::check()) { $grade = Grades::where('id_user', '=', Auth::user()->id)->where('id_recipe', '=', $recipe_id); if ($grade->count()) { $rating = $grade->first()->grade; } } return view('recipes')->with(['recipe' => $recipe, 'ingredient' => $ingredient, 'rating' => $rating]); }