Example #1
0
 /**
  * Reschedule an existing event.
  *
  * @param  Event  $oldEvent
  * @param  array  $data
  * @return Event
  * @throws Exception
  */
 public function reschedule(Event $oldEvent, array $data)
 {
     try {
         DB::beginTransaction();
         // Recreate venue
         $newVenue = $oldEvent->venue->replicate();
         if (is_array($data['venue']) && count($data['venue'])) {
             $newVenue->fill($data['venue']);
         }
         $newVenue->save();
         // Recreate event
         $newEvent = $oldEvent->replicate();
         if (is_array($data['event']) && count($data['event'])) {
             $newEvent->fill($data['event']);
         }
         $newEvent->status_id = EventStatus::ACTIVE;
         $newEvent->venue_id = $newVenue->id;
         $newEvent->save();
         DB::commit();
         return $newEvent;
     } catch (\Exception $e) {
         DB::rollBack();
         throw $e;
     }
 }