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 search($arrayParam) { return Ingredient::where($arrayParam)->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; }