SendEmailNotification.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. public $view;
  12. /**
  13. * SendEmailNotification constructor.
  14. * @param $objToJson
  15. * @param $view
  16. */
  17. public function __construct($objToJson, $view)
  18. {
  19. $this->objToJson = $objToJson;
  20. $this->view = $view;
  21. }
  22. /**
  23. * Get the notification's delivery channels.
  24. *
  25. * @param mixed $notifiable
  26. * @return array
  27. */
  28. public function via($notifiable): array
  29. {
  30. return ['mail'];
  31. }
  32. /**
  33. * Get the mail representation of the notification.
  34. *
  35. * @param mixed $notifiable
  36. * @return MailMessage
  37. */
  38. public function toMail($notifiable): MailMessage
  39. {
  40. $template = json_decode($this->objToJson);
  41. $view = $this->view ? $this->view : 'emails.test';
  42. return (new MailMessage)->view(
  43. $view, ['objToJson' => $template]
  44. )->subject($template->title);
  45. }
  46. /**
  47. * Get the array representation of the notification.
  48. *
  49. * @param mixed $notifiable
  50. * @return array
  51. */
  52. public function toArray($notifiable)
  53. {
  54. return [
  55. //
  56. ];
  57. }
  58. }