Exemplo n.º 1
0
 /**
  * @param AjaxFormRequest $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function subscribeNewsletter(AjaxFormRequest $request)
 {
     $validator = Validator::make($request->all(), $request->rules());
     // check if the validator failed -----------------------
     if ($validator->fails()) {
         return response()->json(array('status' => 'ko', 'errors' => $validator->getMessageBag()->toArray()));
     } else {
         /*
          *  INSERT RECORD IN DB AND NOTIFY SUBSCRIPTION
          *  @event App\Events\Registration\NewsletterSubscribe
          */
         $newsletter = Newsletter::addToDefaultList($request->email);
         return response()->json(array('status' => 'ok', 'msg' => trans('website.newsletter_subscribe_ok')));
     }
 }
 /**
  * Handle the event.
  *
  * @param  UserRegistered  $event
  * @return void
  */
 public function handle(UserRegistered $event)
 {
     //add user to newsletter default  recipient
     // TODO  check if  emailis  already present /create trait)
     Newsletter::addToDefaultList($event->user->email);
 }