laravel-notification-channels / fcm

Firebase Cloud Messaging (FCM) notifications channel for Laravel
https://laravel-notification-channels.com/
MIT License
472 stars 121 forks source link

The registration token is not a valid FCM registration token. #177

Closed burasuk closed 7 months ago

burasuk commented 9 months ago

Sending notifications works via the kreait/laravel-firebase package but not through laravel-notification-channels/fcm.

Versions: laravel-notification-channels/fcm: 3.2 laravel: 10.0

When i run:

$user = User::find(1);
$user->notify(new SomeNotification());

I have an error:

image

My notification definition(not work):

<?php

class SomeNotification extends Notification
{
    use Queueable;

    public function via($notifiable)
    {
        return [FcmChannel::class];
    }

    public function toFcm($notifiable)
    {
        return FcmMessage::create()
            ->setNotification(
                \NotificationChannels\Fcm\Resources\Notification::create()
                    ->setTitle('title')
                    ->setBody('body')
                    ->setImage('https://picsum.photos/id/237/200/300')
            );
    }
}

user class:

<?php 

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Specifies the user's FCM token
     *
     * @return string|array
     */
    public function routeNotificationForFcm()
    {
        return $this->fcm_token;
    }
}

with only laravel-firebase definition(work):

<?php

$fb = \Kreait\Laravel\Firebase\Facades\Firebase::messaging();

$message = \Kreait\Firebase\Messaging\CloudMessage::fromArray([
    'token' => $fcm_token, // token from database
    'notification' => [
        'title' => 'title',
        'body' => 'body',
        'image' => 'https://picsum.photos/id/237/200/300'
    ]
]);

$fb->send($message);
dwightwatson commented 9 months ago

Please try using version 4.x and see if that resolves your issue.

burasuk commented 9 months ago

Error dissapear, but nothing happens, notification not send.

dwightwatson commented 9 months ago

You may need to listen for the notification failed event (see docs) which can help you review the error.