/** * Execute the console command. * * @return mixed */ public function fire() { $selected = new \stdClass(); $protein = Portion::whereHas('type', function ($q) { $q->where('name', 'Protein')->where('include_random', true); })->get(); $random = rand(0, count($protein) - 1); $selected->protein = $protein[$random]; $starch = Portion::whereHas('type', function ($q) { $q->where('name', 'Starch')->where('include_random', true); })->get(); $random = rand(0, count($starch) - 1); $selected->starch = $starch[$random]; $veg = Portion::whereHas('type', function ($q) { $q->where('name', 'Vegetable')->where('include_random', true); })->get(); $random = rand(0, count($veg) - 1); $selected->veg = $veg[$random]; try { $this->line('Protein: ' . $selected->protein->name); $this->line('Starch: ' . $selected->starch->name); $this->line('Vegatable: ' . $selected->veg->name); } catch (\Exception $ex) { $this->error($ex->getMessage()); } }
public function manage($id) { $meal = Meal::find($id); $portions = Portion::all(); $portionTypes = PortionType::all(); return \View::make('meals.add')->with(['portionTypes' => $portionTypes, 'meal' => $meal, 'portions' => $portions])->render(); }
public function getRandom() { $type = $this->portionType->name; $pick = \Excessive\IDF\Models\Portion::whereHas('types', function ($q) use($type) { $q->where('name', $type); })->where('random', true)->get(); $rand = rand(0, $pick->count() - 1); return $pick[$rand]; }
public function ingredientsPost($id) { $portion = Portion::find($id); $name = \Input::get('ingredient-name'); $ingredient = Ingredient::where('name', $name)->first(); if (!$ingredient) { $ingredient = new Ingredient(); $ingredient->name = $name; $ingredient->save(); } $exists = PortionIngredient::where('portion_id', $portion->id)->where('ingredient_id', $ingredient->id)->first(); if ($exists) { return \Redirect::back()->with('error', 'The specified ingredient has already been added'); } $portionIngredient = new PortionIngredient(); $portionIngredient->portion_id = $portion->id; $portionIngredient->ingredient_id = $ingredient->id; $portionIngredient->save(); return \Redirect::back()->with('success', 'You have successfully added an ingredient'); }