SendEmailNotification.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Notifications;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Notifications\Messages\MailMessage;
  6. use Illuminate\Notifications\Notification;
  7. class SendEmailNotification extends Notification implements ShouldQueue
  8. {
  9. use Queueable;
  10. public $objToJson;
  11. /**
  12. * SendEmailNotification constructor.
  13. * @param $objToJson
  14. */
  15. public function __construct($objToJson)
  16. {
  17. $this->objToJson = $objToJson;
  18. }
  19. /**
  20. * Get the notification's delivery channels.
  21. *
  22. * @param mixed $notifiable
  23. * @return array
  24. */
  25. public function via($notifiable): array
  26. {
  27. return ['mail'];
  28. }
  29. /**
  30. * Get the mail representation of the notification.
  31. *
  32. * @param mixed $notifiable
  33. * @return MailMessage
  34. */
  35. public function toMail($notifiable): MailMessage
  36. {
  37. $template = json_decode($this->objToJson);
  38. return (new MailMessage)->view(
  39. 'emails.test', ['objToJson' => $template]
  40. )->subject($template->title);
  41. }
  42. /**
  43. * Get the array representation of the notification.
  44. *
  45. * @param mixed $notifiable
  46. * @return array
  47. */
  48. public function toArray($notifiable)
  49. {
  50. return [
  51. //
  52. ];
  53. }
  54. }