/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, CongvandiUpdateFormRequest $request) { if (Auth::check() && $this->rolechucnangs && $this->rolechucnangs->Sua == 1) { $congvandi = Congvandi::findOrFail($id); // $nowtime = date(); $nowtime = date("m/d/Y", time()); $nowyear = date('Y'); $namky = date('Y-m-d', strtotime(str_replace('/', '-', $request->input('ngayky')))); $namkys = substr($namky, 0, 4); $namphathanh = date('Y-m-d', strtotime(str_replace('/', '-', $request->input('ngayphathanh')))); $namphathanhs = substr($namphathanh, 0, 4); $namluu = date('Y-m-d', strtotime(str_replace('/', '-', $request->input('ngayluu')))); $namluus = substr($namluu, 0, 4); if ($namkys != $nowyear || $namphathanhs != $nowyear || $namluus != $nowyear) { return \Redirect::route('congvandi.edit', $id)->withErrors('Năm văn bản không đúng')->withInput(); } else { //update cong van $congvandi->update(['socongvandichu' => $request->input('socongvandichu'), 'ngayky' => date('Y-m-d', strtotime(str_replace('/', '-', $request->input('ngayky')))), 'noisoanthao_id' => $request->input('noisoanthao'), 'nguoiky_id' => $request->input('nguoiky'), 'danhmucloaicongvan_id' => $request->input('loaicongvan'), 'sobanphathanh' => $request->input('sobanphathanh'), 'trichyeucongvandi' => $request->input('trichyeucongvandi'), 'noinhancongvan' => $request->input('noinhancongvan'), 'danhmucdomat_id' => $request->input('domatcongvan'), 'ngayphathanh' => date('Y-m-d', strtotime(str_replace('/', '-', $request->input('ngayphathanh')))), 'danhmucdokhan_id' => $request->input('dokhancongvan'), 'ngaynhap' => date('Y-m-d', strtotime(str_replace('/', '-', $request->input('ngayluu')))), 'danhmucmucdich_id' => $request->input('mucdichcongvan'), 'danhmuchinhthucchuyen_id' => $request->input('hinhthucchuyen'), 'linhvucchuyende_id' => $request->input('linhvucchuyende'), 'danhmucchuyende_id' => $request->input('chuyende'), 'hantraloi' => date('Y-m-d', strtotime(str_replace('/', '-', $request->input('hantraloi')))), 'noiluu' => $request->input('noiluutru'), 'nguoisua_id' => \Auth::user()->id]); $congvandifind = Congvandi::find($id); //var_dump($congvandifind); $phongs = $request->input('phong'); if ($phongs != NULL) { $congvandifind->danhmucphongs()->sync($phongs); } else { $congvandifind->danhmucphongs()->detach(); } $dois = $request->input('doi'); if ($dois != NULL) { $congvandifind->danhmucdois()->sync($dois); } else { $congvandifind->danhmucdois()->detach(); } $canbos = $request->input('canbo'); if ($canbos != NULL) { $congvandifind->danhmuccanbos()->sync($canbos); } else { $congvandifind->danhmuccanbos()->detach(); } // xu ly file $now_date = str_replace('/', '_', date('d/m/Y')); if ($request->input('upload-file') && $request->hasFile('files')) { $files = $request->file('files'); $newnamefiles = File::savefiles($files, Auth::user()->id); } if ($request->input('upload-file') && $request->hasFile('files') && $newnamefiles) { $congvandifind->files()->sync($newnamefiles); } return \Redirect::route('congvandi.index')->with('message', 'Cập nhật thành công!'); } } else { return \Redirect::route('congvandi.index')->with('message-error', 'Không có quyền truy cập'); } }