/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { if (!Product::find($id)) { // return view('dashboard.supplierProfileEdit'); return redirect()->back()->withErrors(['messages' => "ürün bulunamadı"]); } $product = Product::find($id); if (Auth::user()->id != $product->supplier_id) { //return view('dashboard.supplierProfileEdit'); return redirect()->back()->withErrors(['messages' => "ürün size ait değil"]); } $rules = array('title' => 'required', 'price' => 'required|numeric', 'is_active' => 'required'); // do the validation ---------------------------------- // validate against the inputs from our form $validator = Validator::make($request->all(), $rules); // check if the validator failed ----------------------- if ($validator->fails()) { // get the error messages from the validator $updateProduct = $validator->messages(); // redirect our user back to the form with the errors from the validator // return view('dashboard.supplierProfileEdit'); return back()->withInput()->withErrors($validator); } else { $product->title = $request->input('title'); $product->description = $request->input('description'); $product->price = $request->input('price'); $product->currency_unit_id = CurrencyUnit::where('unit_short_name', 'try')->first()->id; if ($request->input('is_active') == '1') { $product->is_active = $product->isActivable() ? true : false; } else { $product->is_active = false; } $product->update(); $product->categories()->detach(); foreach ($request->input('categories') as $category) { if (Category::find($category)) { $product->categories()->attach(Category::where('id', $category)->first()); } } return redirect()->back()->with('success', ['Ürün bilgileri güncellendi']); } }