/** * Send newsletters to all subscribers * @return View */ public function store() { View::addNamespace('newsletter-email', app_path() . "/StrongCode/Newsletter/Views/{$this->current_theme}/public"); $input = Input::all(); if (isset($input['form_close'])) { return Redirect::to("{$this->link_type}/modules/newsletters"); } $subscribers = NewsletterSubscriber::get()->fetch('email'); Newsletter::create($input); try { foreach ($subscribers as $subscriber) { Mail::queue('newsletter-email::newsletter', $input, function ($email_message) use($input, $subscriber) { $email_message->from(Config::get('mail.username')); $email_message->to($subscriber)->subject($input['subject']); }); } } catch (Exception $e) { return Redirect::back()->withInput()->with('error_message', $e->getMessage()); } $redirect = isset($input['form_save']) ? "{$this->link_type}/modules/newsletters" : "{$this->link_type}/modules/newsletters/create"; return Redirect::to($redirect)->with('success_message', 'The newsletter was sent.'); }
/** * Remove the specified subscriber from storage. * * @param int $id * @return View */ public function destroy($id = null) { // If multiple ids are specified if ($id == 'multiple') { $selected_ids = trim(Input::get('selected_ids')); if ($selected_ids == '') { return Redirect::back()->with('error_message', trans('error_messages.nothing_selected_delete')); } $selected_ids = explode(' ', $selected_ids); } else { $selected_ids = array($id); } foreach ($selected_ids as $id) { $subscriber = NewsletterSubscriber::findOrFail($id); $subscriber->delete(); } $wasOrWere = count($selected_ids) > 1 ? 's were' : ' was'; $message = 'The subscriber' . $wasOrWere . ' deleted.'; if (count($selected_ids) > 1) { $message = trans('success_messages.subscribers_delete'); } else { $message = trans('success_messages.subscriber_delete'); } return Redirect::to("{$this->link_type}/modules/newsletters/subscribers")->with('success_message', $message); }