/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit(Request $request, $id) { $food = Food::where('id', $id)->first(); $brands = Brand::orderBy('name', 'asc')->get(); if ($food && ($request->user()->id == $food->user_id || $request->user()->is_admin())) { return view('foods.edit')->with('food', $food)->withBrands($brands); } return redirect('/food/index')->withErrors('you have not sufficient permissions'); }
public function getNextFood($currfood) { $food = new Food(); $nextFood = $food->where('id', '>', $currfood->id)->orderBy('id', 'asc')->first(); if (!$nextFood) { $nextFood = $food->where('id', '<', $currfood->id)->orderBy('id', 'asc')->first(); } return $nextFood->toArray(); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $foods = Food::where('category_id', $id)->get(); $category = $this->category->find($id); return view('foods.category', compact('foods', 'category')); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show(Request $request, $id) { $brand = Brand::where('id', $id)->first(); $brand_foods = Food::where('brand_id', $id)->get(); return view('brands.show')->with('brand', $brand)->with('brand_foods', $brand_foods); }
/** * Display basic order page. * * @param int $id * @return \Illuminate\Http\Response */ public function welcomeToGo($id) { $meals = Food::where('type', 'meal')->get(); $desserts = Food::where('type', 'dessert')->get(); $drinks = Food::where('type', 'drink')->get(); return view('tables.welcomeToGo', ['id' => $id, 'meals' => $meals, 'desserts' => $desserts, 'drinks' => $drinks]); }
public function getFoodSuggestion() { $age = Carbon::Parse($this->bdate)->diffInYears(); $ageRange = AgeRange::where('min_age', '<=', $age)->where('max_age', '>=', $age)->first(); $gender = $this->gender == 1 ? 'F' : 'M'; if ($this->getFoodHistory()->first() == null) { $foodSuggestion = \DB::select(\DB::raw(' SELECT foods.*, SUM(fn.amount_in_food / rem_nutr.remaining_val) / (2000 / foods.calories) as score FROM foods INNER JOIN food_nutrient AS fn ON foods.id = fn.food_id INNER JOIN (SELECT users.id, daily_value AS remaining_val, nutrient_id FROM users INNER JOIN recommended_values WHERE users.id = ' . $this->id . ' AND recommended_values.age_range = ' . $ageRange->id . ' AND recommended_values.sex = \'' . $gender . '\' GROUP BY nutrient_id) AS rem_nutr ON rem_nutr.nutrient_id = fn.nutrient_id and foods.id not in (select food_id from food_restriction as fr inner join restriction_user as ru on ru.restriction_id = fr.restriction_id where user_id = ' . $this->id . ') GROUP BY foods.id order by score DESC, foods.id, fn.nutrient_id;')); } else { $foodSuggestion = \DB::select(\DB::raw(' SELECT foods.*, SUM(fn.amount_in_food / rem_nutr.remaining_val) / (2000 / foods.calories) as score FROM foods INNER JOIN food_nutrient AS fn ON foods.id = fn.food_id INNER JOIN (SELECT users.id, fn.nutrient_id, nutr.daily_value - SUM((quantity * amount_in_food / 100)) AS remaining_val FROM users INNER JOIN user_history AS uh ON users.id = uh.user_id INNER JOIN food_nutrient AS fn ON fn.food_id = uh.food_id INNER JOIN (SELECT nutrient_id, daily_value FROM recommended_values WHERE age_range = ' . $ageRange->id . ' AND sex = \'' . $gender . '\') AS nutr ON nutr.nutrient_id = fn.nutrient_id WHERE timestamp > DATE_SUB(NOW(), INTERVAL 24 HOUR) AND users.id = ' . $this->id . ' GROUP BY nutrient_id) AS rem_nutr ON rem_nutr.nutrient_id = fn.nutrient_id and foods.id not in (select food_id from food_restriction as fr inner join restriction_user as ru on ru.restriction_id = fr.restriction_id where user_id = ' . $this->id . ') GROUP BY foods.id order by score DESC, foods.id, fn.nutrient_id;')); } $random = rand(0, 200); $foodReturn = Food::where('name', $foodSuggestion[$random]->name)->first(); return $foodReturn; }
public static function SearchByName($name, $restrictions = []) { return Food::where('name', 'LIKE', $name . '%')->RestrictedBy($restrictions)->get(); }