예제 #1
0
 /**
  * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function doEdit()
 {
     $input = Request::all();
     $rules = ['name_pt' => 'required', 'name_en' => 'required', 'description_pt' => 'required', 'description_en' => 'required', 'tags' => 'required', 'duration' => 'required', 'target' => 'required', 'subject' => 'required', 'difficulty' => 'required', 'interaction' => 'required'];
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         // get the error messages from the validator
         $messages = $validator->messages();
         // redirect our user back to the form with the errors from the validator
         return redirect('labs/' . $input['id'] . '/edit')->withErrors($validator);
     } else {
         $lab = Labs::find($input['id']);
         //Image handling
         if (empty($input['thumbnail'])) {
             $input['thumbnail'] = $lab->thumbnail;
         } else {
             $tmp_path = $input['thumbnail']->getRealPath();
             $extension = $input['thumbnail']->getClientOriginalExtension();
             $path = '/img/exp/' . uniqid() . '.' . $extension;
             //Image::make($tmp_path)->save(base_path() . '/public' . $path);
             Image::make($tmp_path)->resize(null, 300, function ($constraint) {
                 $constraint->aspectRatio();
             })->save(base_path() . '/public' . $path);
             $input['thumbnail'] = $path;
         }
         //Array
         $input['target'] = arrayToString($input['target']);
         $input['subject'] = arrayToString($input['subject']);
         //Package
         if (!empty($input['package'])) {
             File::deleteDirectory(public_path('exp_data/' . $lab->id));
             unzipLab($input['package']->getRealPath(), $lab->id);
             unset($input['package']);
         }
         unset($input['_token']);
         //echo $input['maintenance'];die;
         if (array_key_exists("maintenance", $input)) {
             $input['maintenance'] == 'on' ? $input['maintenance'] = '1' : ($input['maintenance'] = '0');
         }
         if (array_key_exists("queue", $input)) {
             $input['queue'] == 'on' ? $input['queue'] = '1' : ($input['queue'] = '0');
         }
         Labs::where('id', '=', $input['id'])->update($input);
         return redirect('labs');
     }
 }