/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update($id, Request $request) { $productModel = Products::findOrFail($id); if (isset($request['attach_file']) && $request['attach_file']) { $attachmentFields = $this->attachFileValidator($request); $productModel->attachments()->save(new \App\Models\Attachments($attachmentFields)); return Redirect::back()->withInput($request->except(["attached_file"])); } if (isset($request['add_Product_Focus_Sub_type']) && $request['add_Product_Focus_Sub_type']) { $producFocusSubTypeField = $this->addProducFocusSubTypeValidator($request); $productModel->focusSubType()->save(ProductFocusSubType::findOrNew($producFocusSubTypeField["id_Product_Focus_Sub_Type"])); return Redirect::back()->withInput($request->except(["add_Product_Focus_Sub_type"])); } if (isset($request['add_competitor']) && $request['add_competitor']) { $competitorProductField = $this->addCompetitorProductValidator($request); $productModel->competitor()->save(Products::findOrNew($competitorProductField['id_Competitor_Product'])); return Redirect::back()->withInput($request->except(["add_competitor"])); } $productsFields = $this->productValidator($request); $productModel->fill($productsFields)->save(); $this->storeRelatedData($request, $productModel); return redirect(route('admin.products.index'))->with('flash', 'The Product was updated'); }
public function saveObjectRelation(Request $request, $newsModel) { DB::table('News_Company')->where("id_News", "=", $newsModel->id_News)->delete(); DB::table('News_Product')->where("id_News", "=", $newsModel->id_News)->delete(); DB::table('News_Employee')->where("id_News", "=", $newsModel->id_News)->delete(); foreach ($newsModel->target as $relationTarget) { $matches = preg_grep('/^' . $relationTarget . "_*/i", array_keys($request->all())); foreach ($matches as $targetItem) { if ($request->get($targetItem) == "on") { $ObjectTrgetId = str_replace($relationTarget . "_", "", $targetItem); switch ($relationTarget) { case 'Companies': $newsModel->company()->save(Companies::findOrNew($ObjectTrgetId)); break; case 'People': $employeeModel = Employee::where("id_People", "=", $ObjectTrgetId)->first(); //dd($employeeModel); $newsModel->employee()->save(Employee::findOrNew($employeeModel->id_Employee)); break; case 'Vertical': break; case 'Products': $newsModel->product()->save(Products::findOrNew($ObjectTrgetId)); break; case 'Events': break; } } } } }