public function deleteMrp($id) { Mrp::destroy($id); return response()->json('true'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // $this->validate($request, ['product_name' => 'required', 'category_id' => 'required']); $product = Product::find($id); $input = $request->all(); //dd($input); $product->fill($input); if (!$request->has('out_of_stock')) { $product->out_of_stock = 0; } if (!$request->has('active')) { $product->active = 0; } $product->save(); $mrpInput = ['qty' => $request->mrp_qty, 'unit_id' => $request->mrp_unit_id, 'mrp' => $request->mrp_mrp]; $mrp = Mrp::firstOrNew(array('product_id' => $id)); $mrp->fill($mrpInput); $mrp->save(); if ($request->hasFile('prod_image')) { $images = $request->file('prod_image'); $files = $_FILES; foreach ($_FILES['prod_image']['tmp_name'] as $key => $tmp_name) { if (strlen($_FILES['prod_image']['name'][$key]) > 0) { $tmp_name = $_FILES['prod_image']['tmp_name'][$key]; $img_name = $_FILES['prod_image']['name'][$key]; $fileimage = Img::make($tmp_name); if ($fileimage->save(public_path() . '/images/products/' . $img_name)) { $newImage = Image::create(['image_name' => $img_name]); $product->images()->attach($newImage->id); } } } } //dd('images uploaded'); $description = Description::firstOrNew(array('product_id' => $id)); $description->description = $request->description; $description->save(); return redirect()->route('admin.product.index'); }