/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Event $event, CreateEventRequest $request)
 {
     $ext1 = $request->file('image_home')->getClientOriginalExtension();
     $ext2 = $request->file('image_away')->getClientOriginalExtension();
     $event = $event->create($request->all());
     $imageName1 = $event->id . "." . $ext1;
     $imageName2 = $event->id . "." . $ext2;
     $request->file('image_home')->move(base_path() . '/public/img/uploads/home/', $imageName1);
     Image::make(base_path() . '/public/img/uploads/home/' . $imageName1, array('width' => 125, 'height' => 100))->save(base_path() . '/public/img/uploads/home/' . $imageName1);
     $request->file('image_away')->move(base_path() . '/public/img/uploads/away/', $imageName2);
     Image::make(base_path() . '/public/img/uploads/away/' . $imageName2, array('width' => 125, 'height' => 100))->save(base_path() . '/public/img/uploads/away/' . $imageName2);
     $event->update(array('image_home' => $imageName1));
     $event->update(array('image_away' => $imageName2));
     Session::flash('message', 'The event was successfully added!.');
     Session::flash('flash_type', 'alert-success');
     return redirect('events');
 }
 public function update(Requests\CreateEventRequest $request, $id)
 {
     $params = $request->except(['_token']);
     $date = \DateTime::createFromFormat('m/d/Y', $params['date']);
     $params['date'] = $date->format('Y-m-d');
     $existingEvent = Event::find($id);
     if ($existingEvent) {
         $existingEvent->update($params);
         // managed removed images
         if (isset($params['rem_files'])) {
             $remainingImgIds = $params['rem_files'];
             foreach ($remainingImgIds as $fileId) {
                 $imgFile = File::find($fileId);
                 if ($imgFile) {
                     try {
                         // delete from db
                         $imgFile->delete();
                         // delete from local storage
                         \Illuminate\Support\Facades\File::delete(MyHelper::getImageFromStorage($existingEvent->id, $imgFile->new_filename));
                         // unbind from event
                         DB::table('event_files')->where('event_id', $existingEvent->id)->where('file_id', $fileId)->delete();
                     } catch (\Exception $e) {
                         Log::info($e->getMessage());
                     }
                 }
             }
         }
         $hasAttachment = $request->hasFile('files');
         if ($hasAttachment) {
             $images = $request->file('files');
             $this->handleAttachedImages($images, $existingEvent->id);
         }
         $request->session()->flash("notif", "Event successfully updated");
     } else {
         $request->session()->flash("notif", "The requested event is not available");
     }
     return redirect('events');
 }