protected function handleUnsubscribe() { if (!isset($this->subscriber->pivot)) { return 'You are already unsubscribed from our mailing list!'; } $pivot = $this->subscriber->pivot; if ($pivot->stop_at) { return 'You are already unsubscribed from our mailing list!'; } $pivot->stop_at = $this->campaign->freshTimestamp(); $pivot->read_at = $this->campaign->freshTimestamp(); $pivot->save(); $this->campaign->count_read++; $this->campaign->count_stop++; $this->campaign->save(); $this->subscriber->confirmed_at = null; $this->subscriber->unsubscribed_at = $this->subscriber->freshTimestamp(); $this->subscriber->save(); // @todo Template + Language return '<html><head><title>Unsubscribe successful</title></head><body><h1>Unsubscribe successful</h1><p>Your email has been successfully unsubscribed from this list!</p></body></html>'; }
/** * Binds all subscribers from the campaign groups to the message. */ public function bindGroupSubscribers($campaign) { $groups = $campaign->groups; if (!is_array($groups)) { return; } /* * Get all group subscriber emails and info */ $groupSubscribers = []; foreach ($groups as $groupType) { $groupSubscribers = $groupSubscribers + $this->getGroupRecipientsData($groupType); } /* * Pair them to existing subscribers, or create them */ $allSubscribers = Subscriber::lists('id', 'email'); $ids = []; foreach ($groupSubscribers as $email => $info) { /* * New subscriber */ if (!isset($allSubscribers[$email])) { $info['email'] = $email; $subscriber = new Subscriber(); $subscriber->forceFill($info); $subscriber->confirmed_at = Carbon::now(); $subscriber->save(); $ids[] = $subscriber->id; } else { $ids[] = $allSubscribers[$email]; } } /* * Sync to the campaign */ if (count($ids) > 0) { $campaign->subscribers()->sync($ids, false); } }