Example #1
0
 public function store()
 {
     $rules = array('titulo' => 'required|max:25', 'descripcion' => 'required|max:40', 'imagen' => 'required|image', 'tags' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return redirect(route('post.create'))->withErrors($validator)->withInput(Input::all());
     } else {
         $image = Input::file('imagen');
         $filename = time() . '.' . $image->getClientOriginalExtension();
         $pathS = public_path('images\\portfolio\\small\\' . $filename);
         $pathL = public_path('images\\portfolio\\large\\' . $filename);
         $rps = 'images\\portfolio\\small\\' . $filename;
         $rpl = 'images\\portfolio\\large\\' . $filename;
         \Intervention\Image\Facades\Image::make($image->getRealPath())->resize(290, 217)->save($pathS);
         \Intervention\Image\Facades\Image::make($image->getRealPath())->save($pathL);
         $post = $this->savePost(Input::get(), $rps, $rpl);
         if (Input::get('tags') != '') {
             $tags = explode(',', Input::get('tags'));
             foreach ($tags as $tag) {
                 $tag_ref = \App\Models\Tag::whereClave($tag)->first();
                 if (is_null($tag_ref)) {
                     $tag_ref = new \App\Models\Tag();
                     $tag_ref->clave = $tag;
                     $post->tags()->save($tag_ref);
                 } else {
                     $post->tags()->attach($tag_ref->id_tag);
                 }
             }
         }
         return redirect('post/create')->with('ok', 'Elemento Insertado Correctamente');
     }
 }