FcmChannel.php 647 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Services\Fcm;
  3. use Illuminate\Notifications\Notification;
  4. class FcmChannel
  5. {
  6. public function __construct(
  7. protected FcmService $fcm,
  8. ) {}
  9. public function send(object $notifiable, Notification $notification): void
  10. {
  11. if (!method_exists($notification, 'toFcm')) {
  12. return;
  13. }
  14. $data = $notification->toFcm($notifiable);
  15. $this->fcm->send(
  16. token: $data['to'],
  17. title: $data['notification']['title'] ?? '',
  18. body: $data['notification']['body'] ?? '',
  19. image: $data['notification']['image'] ?? null,
  20. );
  21. }
  22. }