示例#1
0
 public function updateArt(Request $request)
 {
     $artid = Input::get('txt_artid');
     $image = Input::file('txt_thumb');
     $thumb = '';
     if ($image) {
         $file = array('txt_thumb' => Input::file('txt_thumb'));
         $validator = Validator::make($file, $this->rules_thumb);
         $validator->setAttributeNames(array('txt_thumb' => 'Thumbnail'));
         if ($validator->fails()) {
             return redirect('art/ediArt/' . $artid)->withErrors($validator)->withInput();
         }
         $destinationPath = config('myconfig.upload_folder_images');
         $filename = $image->getClientOriginalName();
         $fullname = date('dmYHis') . '.' . $filename;
         $green = $image->move($destinationPath, $fullname);
         $thumb = $destinationPath . '/' . $fullname;
         //Delete old file
         if (Input::has('txt_thumb_old')) {
             File::delete(Input::get('txt_thumb_old'));
         }
     }
     $validator = Validator::make($request->all(), $this->rules);
     $validator->setAttributeNames($this->niceNames);
     if ($validator->fails()) {
         return redirect('art/editArt')->withErrors($validator)->withInput();
     }
     $art = m_art::find($artid);
     $art->title = Input::get('txt_title');
     $art->summary = Input::get('txt_summ');
     $art->content = Input::get('txt_content');
     $art->status = Input::get('cb_status');
     $art->catid = Input::get('cb_cat');
     $art->chby = Session::get('usrid');
     $art->slug = str_slug(Input::get('txt_title'), '-');
     $art->id_gallery = Input::get('txt_galleryid');
     $art->tag = Input::get('txt_tag');
     if ($image) {
         $art->thumb = $thumb;
     }
     if ($art->save()) {
         return Redirect::to('art/listArt')->with('success', 'Article was updated successfully!');
     }
 }