/** * @param string $eventId * @param string $registrationType * @throws \Acme\Core\Exceptions\EntityNotFoundException * @return \Illuminate\Http\RedirectResponse * Accessed through post form request */ public function subscribe($eventId = '', $registrationType = '') { $userId = Auth::user()->id; $eventId = empty($eventId) ? Input::get('event_id') : $eventId; $registrationType = empty($registrationType) ? Input::get('registration_type') : $registrationType; $subscription = $this->subscriptionRepository->findByEvent($userId, $eventId); $event = $this->eventRepository->findById($eventId); // If not a valid event if (!$event) { return Redirect::action('EventsController@show', $eventId)->with('warning', trans('word.system_error')); } // if event is currently going on // if ( $this->eventRepository->ongoingEvent($event->date_start, $event->date_end) ) { // // return Redirect::action('EventsController@show', $eventId)->with('warning', trans('general.event_ongoing')); // } // If event is Expired // if ( $this->eventRepository->eventExpired($event->date_start) ) { // // return Redirect::action('EventsController@show', $eventId)->with('warning', trans('word.event_expired')); // } // If no subscription entry in the database if (!$subscription) { // create a subscription $subscription = $this->subscriptionRepository->create(['user_id' => $userId, 'event_id' => $eventId, 'status' => 'PENDING', 'registration_type' => $registrationType]); } // Subscribe the user to the event $subscriber = new Subscriber($subscription); $subscriber = $subscriber->subscribe(); if ($subscriber->messages->has('errors')) { // redirect with first error as an array return Redirect::home()->with('errors', [$subscriber->messages->first('errors')]); } else { // If no errors occured while subscription process return Redirect::action('EventsController@getSuggestedEvents', $eventId)->with('success', trans('general.subscription_check_email')); } }