/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // $input = $request->all(); $validator = Validator::make($input, ['price' => 'required', 'job_type' => 'required', 'job_id' => 'required', 'paper_id' => 'required']); if ($validator->fails()) { return \Redirect::back()->withErrors($validator)->withInput(); } array_forget($request, "_token"); $all_request = $request->all(); $price = Price::find($id); $papers = Paper::all(); $jobs = Job::all(); foreach ($all_request as $key => $value) { $price->{$key} = $value; } $price->update(); $prices = Price::all(); if ($request->ajax()) { if ($prices) { foreach ($prices as $price) { echo "\n <tr>\n <td>{$price->id}</td>\n <td>"; foreach ($papers as $paper) { if ($paper->id == $price->paper_id) { $paperid = $paper->name; echo $paper->name . ", " . $paper->size; } } echo " </td>\n <td>"; foreach ($jobs as $job) { if ($job->id == $price->job_id) { $jobid = $job->name; echo $job->name; } } echo "</td>\n <td>{$price->job_type}</td>\n <td>{$price->price}</td>\n <td><button class='edtPriceLink btn-primary' cpaperid='{$paperid}' cjobtype='{$price->job_type}' cid='{$price->id}' cjobid='{$price->job_id}' cprice='{$price->price}'><span class='glyphicon glyphicon-pencil'></span></button></td>\n <td><button class='btn-danger' data-target='#myModalPaperEdit' data-toggle='modal'><span class='glyphicon glyphicon-trash'></span></button></td>\n </tr>\n "; } } exit; } else { try { if ($price->update()) { \Session::flash("success_message", "New Price Record Updated Successfully"); return \Redirect::back(); } } catch (\Illuminate\Database\QueryException $e) { \Session::flash("error_message", $e->getMessage()); return \Redirect::back(); } catch (\PDOException $e) { \Session::flash("error_message", $e->getMessage()); return \Redirect::back(); } catch (\Exception $e) { \Session::flash("error_message", $e->getMessage()); return \Redirect::back(); } } return View("settings.priceedit", ['jobs' => $jobs, 'papers' => $papers, 'title' => 'Job Setting']); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $location_id, $id) { $location = Location::find($location_id); $price = Price::find($id); $price->type = $request->type; $price->price = $request->price; $price->price_date = $request->price_date; $price->location()->associate($location); $price->save(); return redirect()->action('LocationController@show', $price->location->id); }
public function updatePrice(Request $request, $id) { $price = Price::find($id); if (!$price) { return response('Produkt nie został odnaleziony.', 404); } if ($request->input('product')) { $price->product = $request->input('product'); } if ($request->input('price')) { $price->price = $request->input('price'); } $price->save(); return response()->json($price); }
public function updatePrice(Request $request, $id) { $price = Price::find($id); $price->fill($request->all()); $price->save(); return response()->json('true'); }
/** * @param $id * * @return mixed */ private function getPriceById($id) { return Price::find($id); }