/** * Run the database seeds. * * @return void */ public function run() { $webinars = []; $users = [1, 2, 3]; foreach ($users as $uid) { for ($i = 0; $i < 5; $i++) { $faker = Faker\Factory::create(); $webinar = ['user_id' => $uid, 'title' => $faker->realText($faker->numberBetween(60, 80)), 'hosts' => $faker->realText($faker->numberBetween(60, 80)), 'share' => $faker->realText($faker->numberBetween(30, 50)), 'description' => $faker->realText($faker->numberBetween(120, 180)), 'starts_on' => $faker->dateTime($min = 'now'), 'duration' => rand(1, 4) . 'h', 'timezone' => 'EDT']; $webinar = Webinar::create($webinar); $hashedId = hashWebinar($webinar->id); $webinar->uuid = $hashedId; $webinar->save(); $webinar->subscribers_lists()->attach(rand(1, 3)); $webinar_subscriber_list = SubscribersList::whereWebinarId($webinar->id)->first(); $webinar->signup_subscribers_lists()->attach($webinar_subscriber_list->id); } } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request, $webinarId) { ini_set("max_execution_time", 0); try { $webinar = Webinar::find($webinarId); $webinar_uuid = hashWebinar($webinarId); $user_id = Auth::user()->id; $subscribers_lists = $webinar->subscribers_lists()->get(); $webinar_signup_subscribers_lists = $webinar->signup_subscribers_lists()->get(); $input = $request->all(); if (count($subscribers_lists) > 0) { $subject = $input['subject']; $body = $input['content']; $smtp_method = $input['smtp_method'][0]; $setting = Setting::whereName('custom_domain')->where('customer_id', '=', $user_id)->first(); if (!$setting) { return redirect()->back()->with("error", "Custom Domain is not Set."); } $smtp = Smtp::find($smtp_method); if (!$smtp) { return redirect()->back()->with("error", "No SMTP Method Found"); } $custom_domain = $setting->value; config(["mail.driver" => "smtp", "mail.host" => $smtp->host, "mail.port" => $smtp->port, "mail.from.address" => $smtp->from_email, "mail.from.name" => $smtp->from_name, "mail.encryption" => $smtp->protocol, "mail.username" => $smtp->username, "mail.password" => $smtp->password]); // General Subscribers List if ($subscribers_lists) { foreach ($subscribers_lists as $subscriber_list) { $subscribers = $subscriber_list->activeSubscribers()->get(); if (count($subscribers) > 0) { foreach ($subscribers as $subscriber) { $subscriber_hash = $subscriber->uuid; $subscriber_name = $subscriber->first_name . ' ' . $subscriber->last_name; $to_email = $subscriber->email; $webinar_url = "http://" . $custom_domain . "/webinar/" . $webinar_uuid . "/" . $subscriber_hash; $emailData = ['body' => $body, 'subscriber_name' => $subscriber_name, 'webinar_url' => $webinar_url]; Mail::send('emails.webinar_invite_email', $emailData, function ($message) use($subject, $to_email, $subscriber_name) { $message->subject($subject); $message->from('*****@*****.**', 'Webinar Admin'); $message->to($to_email, $subscriber_name); }); } } } } // Send Email to Webinar Specific Subscribers if ($webinar_signup_subscribers_lists) { foreach ($webinar_signup_subscribers_lists as $subscriber_list) { $subscribers = $subscriber_list->activeSubscribers()->get(); if (count($subscribers) > 0) { foreach ($subscribers as $subscriber) { echo $subscriber->id . "<br/>"; $subscriber_hash = $subscriber->uuid; $subscriber_name = $subscriber->first_name . ' ' . $subscriber->last_name; $to_email = $subscriber->email; $webinar_url = "http://" . $custom_domain . "/webinar/" . $webinar_uuid . "/" . $subscriber_hash; $emailData = ['body' => $body, 'subscriber_name' => $subscriber_name, 'webinar_url' => $webinar_url]; Mail::send('emails.webinar_invite_email', $emailData, function ($message) use($subject, $to_email, $subscriber_name) { $message->subject($subject); $message->to($to_email, $subscriber_name); }); } } } } } return redirect()->back()->with("status", "Mail Sent Succesfully"); } catch (\Exception $e) { } return redirect()->back(); }
public function postClone(WebinarStoreRequest $request, $user_id, $webinar_id) { $sourceWebinar = Webinar::where('uuid', '=', $webinar_id)->first(); $user = User::find($user_id); $input = $request->input(); $starts = trim(explode(',', $input['date_starts_on'])[1]) . ' ' . $input['time_starts_on']; $starts = Carbon::createFromFormat('d F Y h:i A', $starts)->toDateTimeString(); $input['starts_on'] = $starts; $cloneWebinar = Webinar::create($input); $cloneWebinar->uuid = hashWebinar($cloneWebinar->id); foreach ($input['subscribers_lists'] as $listId) { $cloneWebinar->subscribers_lists()->attach($listId); } if (isset($input['excluded_subscribers_lists'])) { foreach ($input['excluded_subscribers_lists'] as $listId) { $cloneWebinar->excluded_subscribers_lists()->attach($listId); } } if (isset($input['panelists'])) { foreach ($input['panelists'] as $panelist) { $cloneWebinar->panelists()->attach($panelist); } } if (isset($input['signup_subscribers'])) { foreach ($input['signup_subscribers'] as $listId) { $cloneWebinar->signup_subscribers_lists()->attach($listId); } } $cloneWebinar->save(); return redirect()->route('users.webinars.edit', [$user_id, $cloneWebinar->uuid]); }