Created
July 13, 2020 09:23
-
-
Save bobbybouwmann/ecb7cfd50f76048504dc604f9e5129ac to your computer and use it in GitHub Desktop.
Revisions
-
bobbybouwmann created this gist
Jul 13, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ <?php final class CardActivationReminder extends Notification implements MailNotificationInterface { use Queueable; /** * @var User */ private $user; /** * @var Card */ private $card; /** * @var bool */ private $hidden; public function __construct(User $user, Card $card, $hidden = false) { $this->user = $user; $this->card = $card; $this->hidden = $hidden; } public function via($notifiable): array { return [SendInBlueChannel::class, 'database']; } public function toSendInBlue($notifiable): SendInBlueMessage { return new SendInBlueMessage($this->sendInBlueKey()); } public function toArray($notifiable): array { return [ 'sendToEmail' => $this->user->email, 'cardId' => $this->card->id, 'hidden' => $this->hidden, 'subject' => $this->sendInBlueKey(), ]; } public function sendInBlueKey(): string { return Emails::CARD_ACTIVATION_REMINDER; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ <?php final class EmailChangedEmail extends Notification implements ShouldQueue, MailNotificationInterface { use Queueable; /** * @var string */ public $previousEmail; /** * @var string */ public $newEmail; /** * @var string */ private $sendToEmail; public function __construct(string $previousEmail, string $newEmail, string $sendToEmail) { $this->previousEmail = $previousEmail; $this->newEmail = $newEmail; $this->sendToEmail = $sendToEmail; } public function via($notifiable): array { return [SendInBlueChannel::class, 'database']; } public function toSendInBlue($notifiable): SendInBlueMessage { $user = User::where('email', $this->previousEmail) ->orWhere('email', $this->newEmail) ->first(); return (new SendInBlueMessage($this->sendInBlueKey())) ->language($user->language) ->params([ 'previousEmail' => $this->previousEmail, 'newEmail' => $this->newEmail, ]); } public function toArray($notifiable): array { return [ 'sendToEmail' => $notifiable instanceof AnonymousNotifiable ? $this->sendToEmail : $notifiable->email, 'previousEmail' => $this->previousEmail, 'newEmail' => $this->newEmail, 'subject' => $this->sendInBlueKey(), ]; } public function sendInBlueKey(): string { return Emails::EMAIL_CHANGED; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <?php // Used in a scheduled command that doesn't need to send the email and only store it in the database Notification::route('database', $user->notifications()) ->notifyNow(new CardActivationReminder($user, $card, true)); // A method on the Uer model for a single card public function sendCardActivationReminder(User $user, Card $card): void { $this->notify(new CardActivationReminder($user, $card)); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ <?php final class SendEmailChangedOldEmailNotification { public function handle(EmailChanged $event): void { $notification = new EmailChangedEmail($event->previousEmail, $event->newEmail, $event->previousEmail); Notification::route('sendInBlue', $event->previousEmail) ->route('database', $event->user->notifications()) ->notifyNow($notification); } }