FireBaseNotification.php 1014 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 FireBaseNotification extends Notification
  8. {
  9. use Queueable;
  10. /**
  11. * Create a new notification instance.
  12. */
  13. public function __construct(
  14. private readonly string $title,
  15. private readonly string $body,
  16. )
  17. {}
  18. /**
  19. * Get the notification's delivery channels.
  20. *
  21. * @return array<int, string>
  22. */
  23. public function via(object $notifiable): array
  24. {
  25. return ['fcm'];
  26. }
  27. public function toFcm(object $notifiable): array
  28. {
  29. return [
  30. 'to' => $notifiable->token_fcm,
  31. 'notification' => [
  32. 'title' => $this->title,
  33. 'body' => $this->body,
  34. 'image' => config('app.addr') . '/logo.png', // Optional image URL
  35. ],
  36. ];
  37. }
  38. }