Custom.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Notifications;
  3. use App\Channels\BarkChannel;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Notifications\Messages\MailMessage;
  7. use Illuminate\Notifications\Notification;
  8. use NotificationChannels\Telegram\TelegramChannel;
  9. use NotificationChannels\Telegram\TelegramMessage;
  10. class Custom extends Notification implements ShouldQueue
  11. {
  12. use Queueable;
  13. private $title;
  14. private $content;
  15. public function __construct($title, $content)
  16. {
  17. $this->title = $title;
  18. $this->content = $content;
  19. }
  20. public function via($notifiable)
  21. {
  22. return $notifiable ?? ['mail', BarkChannel::class, TelegramChannel::class];
  23. }
  24. public function toMail($notifiable)
  25. {
  26. return (new MailMessage)
  27. ->subject($this->title)
  28. ->markdown('mail.custom', ['content' => $this->content]);
  29. }
  30. public function toCustom($notifiable)
  31. {
  32. return [
  33. 'title' => $this->title,
  34. 'content' => $this->content,
  35. ];
  36. }
  37. public function toTelegram($notifiable)
  38. {
  39. return TelegramMessage::create()
  40. ->token(sysConfig('telegram_token'))
  41. ->content($this->content);
  42. }
  43. }