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

Call to a member function target() on null #173

Closed masterbater closed 10 months ago

masterbater commented 10 months ago
  "kreait/laravel-firebase": "^5.4",
"laravel-notification-channels/fcm": "^3.2",
dwightwatson commented 10 months ago

Can you please provide more information about the exception. Make sure you've read the docs for the version you're using and not what's in the master branch.

masterbater commented 10 months ago

https://github.com/laravel-notification-channels/fcm#handling-errors The error comes from here

dwightwatson commented 10 months ago

That's the dev-master docs. Please use v4 of this library or go and read the v3 docs to handle removing old tokens.

masterbater commented 10 months ago

I followed got that error "laravel-notification-channels/fcm": "^3.2", Do I need to update to 3.2.1?

masterbater commented 10 months ago
   Error 

  Call to a member function target() on null

  at app/Listeners/DeleteExpiredNotificationTokens.php:17
     13▕     public function handle(NotificationFailed $event): void
     14▕     {
     15▕         $report = Arr::get($event->data, 'report');
     16▕ 
  ➜  17▕         $target = $report->target();
     18▕ 
     19▕         $event->notifiable->notificationTokens()
     20▕             ->where('push_token', $target->value())
     21▕             ->delete();

      +11 vendor frames 

  12  app/Console/Commands/SendReminderTask.php:61
      App\Models\User::notify(Object(App\Notifications\TaskReminderForAcadAndAdmin))
      +12 vendor frames 

  25  artisan:35
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
masterbater commented 10 months ago

Anyway I just get the token like this

<?php

namespace App\Listeners;

use Illuminate\Notifications\Events\NotificationFailed;
use Illuminate\Support\Arr;

class DeleteExpiredNotificationTokens
{
    /**
     * Handle the event.
     */
    public function handle(NotificationFailed $event): void
    {
        $token = Arr::get($event->data, 'token');

        $event->notifiable->notification_tokens()
            ->where('token', $token)
            ->delete();
    }
}
Pangeranmw commented 10 months ago

Anyway, I just got the token like this

<?php

namespace App\Listeners;

use Illuminate\Notifications\Events\NotificationFailed;
use Illuminate\Support\Arr;

class DeleteExpiredNotificationTokens
{
    /**
Handle the event.
     */
    public function handle(NotificationFailed $event): void
    {
        $token = Arr::get($event->data, 'token');

        $event->notifiable->notification_tokens()
            ->where('token', $token)
            ->delete();
    }
}

Can I see your user model? What exactly are 'token' and notification_tokens()?

masterbater commented 10 months ago

Anyway, I just got the token like this

<?php

namespace App\Listeners;

use Illuminate\Notifications\Events\NotificationFailed;
use Illuminate\Support\Arr;

class DeleteExpiredNotificationTokens
{
    /**

Handle the event.

 */
public function handle(NotificationFailed $event): void
{
    $token = Arr::get($event->data, 'token');

    $event->notifiable->notification_tokens()
        ->where('token', $token)
        ->delete();
}

}

Can I see your user model? What exactly are 'token' and notification_tokens()?

I just inspect the structure of the data, notification_tokens() are what you instructed to add to your user model. token its derived from the event data

dd($event->data)