예제 #1
0
 /**
  * Stores Labs data
  *
  * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function store()
 {
     $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', 'thumbnail' => 'required', 'package' => 'required'];
     $validator = Validator::make($input, $rules);
     if ($validator->fails() or empty($input['package'])) {
         // 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/create')->withInput()->withErrors($validator);
     } else {
         //return var_dump($input);
         //Image handling
         $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(240, 180)->save(base_path().'/public'.$path);
         $input['thumbnail'] = $path;
         //Array
         $input['target'] = arrayToString($input['target']);
         $input['subject'] = arrayToString($input['subject']);
         $input['id'] = getLastLabId();
         //Package
         unzipLab($input['package']->getRealPath(), getLastLabId());
         if (array_key_exists("maintenance", $input)) {
             $input['maintenance'] == 'on' ? $input['maintenance'] = '1' : ($input['maintenance'] = '0');
         } else {
             $input['maintenance'] = '0';
         }
         if (array_key_exists("queue", $input)) {
             $input['queue'] == 'on' ? $input['queue'] = '1' : ($input['queue'] = '0');
         } else {
             $input['queue'] = '1';
         }
         Labs::create($input);
         return redirect('labs');
     }
 }