/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //validate this var_dump($request->all()); $input = $request->all(); $params = []; $quantities = $input['quantities'] = explode(',', $input['quantities']); $items = $this->item->getIn('id', explode(',', $input['ids'])); $ctr = 0; $recipe = Recipe::create($request->all()); foreach ($items as $key => $value) { $ing = ['name' => $value['name'] . " for " . $recipe->name, 'recipe_id' => $recipe->id, 'item_id' => $value['id'], 'quantity' => (int) $quantities[$ctr]]; array_push($params, $ing); $ctr++; } $ingredients = Ingredient::insert($params); if ($recipe && $ingredients) { return redirect()->back()->with('flash_message', 'Recipe has been successfully saved.'); } $this->recipe->fdelete($recipe); foreach ($ingredients as $key) { $key->forceDelete(); } return redirect()->back()->withErrors('Could not save recipe'); }
public function recipe(Request $r) { if ($r->has('product_id')) { $p = Product::find($r->get('product_id')); $recipe = $p->recipe; $i = Ingredient::where('recipe_id', '=', $recipe->first()->id)->get(); return ['recipe' => $p->recipe, 'ingredient' => $i->lists('quantity', 'name')]; } }
public function getNullRecipe() { return Ingredient::whereNotIn('id', Recipe::all()->lists('product_id'))->get(); }
public function processcomputation(Request $request) { $input = $request->all(); $data = $input['data']; $products = []; $order = []; foreach ($data as $v) { $product = Product::find($v[0]); $recipe = $product->recipe; foreach ($recipe as $key => $value) { $ingredients = Ingredient::where('recipe_id', '=', $value['id'])->get(); foreach ($ingredients as $ingredient) { array_push($order, ['name' => $ingredient->name, 'quantity' => $ingredient->quantity * $v[1]]); } } } //$product = Product::find($input['data']); $recipe = $product->recipe; return $order; }