/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $subscribers = [["first_name" => "Anik", "last_name" => "Hasan", "email" => "*****@*****.**", "status" => "Active"], ["first_name" => "M", "last_name" => "R", "email" => "*****@*****.**", "status" => "Active"], ["first_name" => "Platon", "last_name" => "Mysnyk", "email" => "*****@*****.**", "status" => "Active"], ["first_name" => "Anik", "last_name" => "Hasan", "email" => "*****@*****.**", "status" => "Active"], ["first_name" => "M", "last_name" => "R", "email" => "*****@*****.**", "status" => "Active"], ["first_name" => "Platon", "last_name" => "Mysnyk", "email" => "*****@*****.**", "status" => "Active"], ["first_name" => "Anik", "last_name" => "Hasan", "email" => "*****@*****.**", "status" => "Active"], ["first_name" => "M", "last_name" => "R", "email" => "*****@*****.**", "status" => "Active"], ["first_name" => "Platon", "last_name" => "Mysnyk", "email" => "*****@*****.**", "status" => "Active"]];
     foreach ($subscribers as $subscriber) {
         $subscriber = Subscriber::create($subscriber);
         $subscriber->subscribers_lists()->attach(rand(1, 3));
     }
 }
 function subscriber()
 {
     $users = User::all();
     foreach ($users as $user) {
         if ($user->email != '*****@*****.**') {
             Subscriber::create(['user_id' => $user->id, 'subscriber_id' => 1]);
         }
     }
 }
 /**
  * Stores bulk subscribers create request.
  *
  * @param  \Illuminate\Http\Request  $request
  */
 public function store(Request $request, $userId, $subscribersListId)
 {
     $subscribers = Input::get('subscribers');
     $list = SubscribersList::find($subscribersListId);
     foreach ($subscribers as $subscriber) {
         if ($list->subscribers()->where('email', $subscriber['email'])->count() == 0) {
             $subscriber['status'] = 'Active';
             $subscriber = Subscriber::create($subscriber);
             $subscriber->uuid = hashSubscriber($subscriber->id);
             $subscriber->save();
             $subscriber->subscribers_lists()->attach($subscribersListId);
         }
     }
 }
 /**
  * Создание нового подписчика
  *
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function create(Request $request)
 {
     $validator = Validator::make($request->all(), ['firstName' => 'required|min:3|max:255', 'lastName' => 'required|min:3|max:255', 'middleName' => 'required|min:3|max:255', 'phoneNumber' => 'required|unique:subscribers,phone_number|regex:/^7[0-9]{10}$/']);
     if ($validator->fails()) {
         Session::flash('subscriberCreateError', 'Возникла ошибка при создании пользователя.');
         return redirect()->back();
     }
     $firstName = $request->input('firstName');
     $lastName = $request->input('lastName');
     $middleName = $request->input('middleName');
     $phoneNumber = $request->input('phoneNumber');
     if (Subscriber::create($firstName, $lastName, $middleName, $phoneNumber)) {
         Session::flash('subscriberCreateSuccess', 'Пользователь успешно создан.');
         return redirect('/subscribers');
     } else {
         Session::flash('subscriberCreateError', 'Возникла ошибка при создании пользователя.');
         return redirect()->back();
     }
 }
 function addLead(Request $request)
 {
     if ($request->ajax()) {
         $input = $request->all();
         $webinar_id = $input['webinar_id'];
         $first_name = $input['first_name'];
         $last_name = $input['last_name'];
         $email = $input['email'];
         $response = array();
         $rules = ['webinar_id' => 'required', 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email'];
         $validator = Validator::make($input, $rules);
         if ($validator->passes()) {
             $webinar = Webinar::find($webinar_id);
             if ($webinar) {
                 $subscriber = Subscriber::whereEmail($email)->first();
                 if (!$subscriber) {
                     $insert = ["first_name" => $first_name, "last_name" => $last_name, "email" => $email, "status" => "Active"];
                     $subscriber = Subscriber::create($insert);
                 }
                 $webinar_signup_subscribers_lists = $webinar->signup_subscribers_lists()->get();
                 foreach ($webinar_signup_subscribers_lists as $webinar_list) {
                     // Attach New Subscriber with Webinar
                     $webinar_list->subscribers()->detach($subscriber->id);
                     $webinar_list->subscribers()->attach($subscriber->id);
                 }
                 $response = array('success' => true);
             } else {
                 $errors = array("Webinar Not Found");
                 $response = array('success' => false, 'errors' => $errors);
             }
         } else {
             $errors = $validator->getMessageBag()->toArray();
             $response = array('success' => false, 'errors' => $errors);
         }
         echo json_encode($response);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(SubscriberCreateRequest $request)
 {
     $subscriber = Subscriber::create($request->subscriberFillData());
     return redirect('/admin/subscribers')->withSuccess('New Subscriber!');
 }
 /**
  * Subscribe the user and sends an email
  * @param  Request $request
  * @return status
  */
 public function postSubscribe(Request $request)
 {
     $this->validate($request, ['email' => 'required|unique:subscribers|max:100']);
     $subscriber = Subscriber::create($request->all('email'));
     //Queue the newsletter confirmation email
     $this->dispatch(new SendNewsletterSubscribedEmail($subscriber));
     return response()->json(['status' => 'ok']);
 }