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')]; } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $input = $request->all(); $extension = "png"; $product = Product::find($input['product_id']); if ($product) { $file = $this->BgcOutput->output($request->get('barcodekey') ? $request->get('barcodekey') : str_pad($input['product_id'], 7, "0", STR_PAD_LEFT), $extension, public_path('img-barcode')); //if($request->has('fastinput'))return redirect()->back()->with('flash_message' , 'Successfully saved barcode. <br/>File:<a href="'.$file.'">View</a>'); if (file_exists(public_path('img-barcode') . '/' . $file)) { $input['imageurl'] = Url('img-barcode') . '/' . $file; $input['barcodekey'] = $request->get('barcodekey') ? str_pad($request->get('barcodekey'), 7, "0", STR_PAD_LEFT) : str_pad($input['product_id'], 7, "0", STR_PAD_LEFT); if ($barcode = $this->save($input)) { $product->barcode_id = $barcode->id; if ($product->save()) { return redirect(route('barcode.show', $file))->with('flash_message', 'Successfully saved barcode. <br/>File:<a href="' . $file . '">View</a>'); } } } } return redirect()->back()->withErrors('Cannot save barcode. Try Again'); }
public function find($id) { return Product::find($id); }
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; }