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

Binding Resolution Exception #157

Closed 1e4 closed 1 year ago

1e4 commented 1 year ago

Hi,

Just adding in FCM to my app and came across this issue

Target [Illuminate\Contracts\Notifications\Dispatcher] is not instantiable while building [App\Console\Commands\TestPushNotification].

I checked the repo for various issues to see if anyone came across it and I couldn't, however took the advice here and used the SDK you use under the hood and that worked, so I know the account credentials are being picked up and the project

        // This works
        $messaging = app('firebase.messaging');
        $message = CloudMessage::withTarget('token', $fcm)
            ->withNotification(Notification::create('Test', 'test')) // optional
        ;

        $messaging->send($message);

However I cannot get it working by using $user->notify()

class PushNotification extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     */
    public function via($notifiable)
    {
        return [FcmChannel::class];
    }

    public function toFcm($notifiable)
    {
        return FcmMessage::create()
            ->setNotification(\NotificationChannels\Fcm\Resources\Notification::create()
                ->setTitle('Account Activated')
                ->setBody('Your account has been activated.')
                ->setImage('http://example.com/url-to-image-here.png'));
    }
}

Do you have any ideas what is going wrong or a direction I should look to debug this more?

Currently using

"laravel-notification-channels/fcm": "^3.2",