/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(ShipRequest $request, $id) { $data = ['name' => $request->get('name'), 'price' => $request->get('price')]; $ship = Ship::find($id); $ship->update($data); return redirect()->route('ship.index'); }
public function update($id, ShipRequest $request) { $ship = Ship::findOrFail($id); $ship->update($request->all()); return redirect('ships'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(ShipRequest $request, $id) { try { if ($request->hasFile('file')) { $fileInfo = $this->uploadFile($request->file('file'), 'ships'); // if upload success if ($fileInfo) { $ship = $this->ship->update($id, $request->only($this->dataGet), $fileInfo['name']); // update file table if isset if (isset($ship->file)) { $file = $ship->file; $file->update($id, $fileInfo); } else { //save info file $file = new FileRepository(new File()); $fileInfo['ship_id'] = $ship->id; $file->create($fileInfo); } } } else { $this->ship->update($id, $request->only($this->dataGet)); } return redirect()->back(); } catch (Exception $e) { return redirect()->back()->withInput()->with('error', 'Không thể truy vấn dữ liệu'); } }