/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $post = new Update();
     $post->title = $request->title;
     $post->content = $request->body;
     $post->published_on = $request->published;
     $post->headline = $request->headline;
     if ($request->expires) {
         $post->expires_on = $request->expires;
     }
     $post->category_id = $request->category;
     if ($post->save()) {
         $files = $request->file('attachments');
         if (count($files) && !is_null($files) && is_array($files) && !is_null($files[0])) {
             mkdir($this->upload_dir . $post->id);
             foreach ($files as $file) {
                 if ($file->isValid()) {
                     if ($file->move($this->upload_dir . $post->id, $file->getClientOriginalName())) {
                         $attachment = new Attachment();
                         $attachment->filename = $file->getClientOriginalName();
                         $attachment->size = $file->getClientSize();
                         $attachment->update_id = $post->id;
                         $attachment->type = pathinfo($this->upload_dir . $post->id . '/' . $file->getClientOriginalName(), PATHINFO_EXTENSION);
                         $attachment->save();
                     }
                 }
             }
         }
         return redirect('about/galleries');
     } else {
         return 'Error';
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['title' => 'required | min:3', 'headline' => 'sometimes|min:3', 'body' => 'sometimes | min:3', 'attachments' => 'required', 'published' => 'required|date', 'expires' => 'sometimes|after:' . $request->published]);
     if ($validator->passes()) {
         $post = new Update();
         $post->title = $request->title;
         $post->content = $request->body;
         $post->published_on = $request->published;
         $post->headline = $request->headline;
         if ($request->expires) {
             $post->expires_on = $request->expires;
         }
         $post->category_id = $request->category;
         if ($post->save()) {
             $files = $request->file('attachments');
             if (count($files) && !is_null($files) && is_array($files) && !is_null($files[0])) {
                 mkdir($this->upload_dir . $post->id);
                 foreach ($files as $file) {
                     if ($file->isValid()) {
                         if ($file->move($this->upload_dir . $post->id, $file->getClientOriginalName())) {
                             $attachment = new Attachment();
                             $attachment->filename = $file->getClientOriginalName();
                             $attachment->size = $file->getClientSize();
                             $attachment->update_id = $post->id;
                             $attachment->type = pathinfo($this->upload_dir . $post->id . '/' . $file->getClientOriginalName(), PATHINFO_EXTENSION);
                             $attachment->save();
                         }
                     }
                 }
             }
             if ($post->attachments()->count() > 0 && $post->featured == '') {
                 $post->featured = $post->attachments()->first()->id;
                 $post->save();
             }
             return redirect('about/galleries');
         } else {
             return 'Error';
         }
     } else {
         return redirect('about/galleries/create')->withInput();
     }
 }