Ejemplo n.º 1
0
 public function update(Requests\CreateEventRequest $request, $id)
 {
     $params = $request->except(['_token']);
     $existingEvent = Calendar::find($id);
     if ($existingEvent) {
         $existingEvent->update($params);
         $request->session()->flash("notif", "schedule successfully updated");
     } else {
         $request->session()->flash("notif", "The requested schedule is not available");
     }
     return redirect('admin/events');
 }
Ejemplo n.º 2
0
 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');
 }