/** * Update the specified resource in storage. * * @param \App\Http\Requests\DepartmentRequest $request * @param \App\Department $department * @return \Illuminate\Http\Response */ public function update(Requests\DepartmentRequest $request, Department $department) { DB::transaction(function () use($department, $request) { $oldKeyword = $department->keyword; $data = ['keyword' => $request->get('keyword'), 'url' => $request->get('url'), 'theme_background_color' => $request->get('theme_background_color'), 'theme_color' => $request->get('theme_color'), 'sort' => $request->get('sort'), 'active' => $request->get('active')]; if ($request->file('image')) { $data['image'] = $request->file('image')->getClientOriginalName(); File::delete('images/' . $department->image); $request->file('image')->move('images/', $request->file('image')->getClientOriginalName()); } $department->update($data); $department->langs()->delete(); $this->addDepartmentLangs($request, $department); if ($department->keyword != $oldKeyword) { File::move('papers/' . $oldKeyword, 'papers/' . $department->keyword); } Cache::forget('departments'); }); return redirect(action('Admin\\DepartmentController@index'))->with('success', 'updated'); }