/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, Background $background) { $background->update($request->except('file')); if ($request->hasFile('file')) { $file = $request->file('file'); $dir = 'img/background'; $name = $background->id() . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); $background->file = $dir . '/' . $name; $background->save(); $file->move($dir, $name); } return redirect()->route('admin.background.show', $background); }