Example #1
0
 /**
  * Handle the unsubscribe.
  *
  * @param string|null $code
  * @param int|null    $subscription
  *
  * @return \Illuminate\View\View
  */
 public function getUnsubscribe($code = null, $subscription = null)
 {
     if ($code === null) {
         throw new NotFoundHttpException();
     }
     $subscriber = Subscriber::where('verify_code', '=', $code)->first();
     if (!$subscriber || !$subscriber->is_verified) {
         throw new BadRequestHttpException();
     }
     if ($subscription) {
         dispatch(new UnsubscribeSubscriptionCommand(Subscription::forSubscriber($subscriber->id)->firstOrFail()));
     } else {
         dispatch(new UnsubscribeSubscriberCommand($subscriber, $subscription));
     }
     return Redirect::route('status-page')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.unsubscribed')));
 }