Call to a member function target() on null
masterbater opened this issue · 8 comments
"kreait/laravel-firebase": "^5.4",
"laravel-notification-channels/fcm": "^3.2",
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.
https://github.com/laravel-notification-channels/fcm#handling-errors
The error comes from here
That's the dev-master docs. Please use v4 of this library or go and read the v3 docs to handle removing old tokens.
I followed got that error
"laravel-notification-channels/fcm": "^3.2",
Do I need to update to 3.2.1?
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();
�[2m+11 vendor frames �[22m
12 app/Console/Commands/SendReminderTask.php:61
App\Models\User::notify(Object(App\Notifications\TaskReminderForAcadAndAdmin))
�[2m+12 vendor frames �[22m
25 artisan:35
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
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();
}
}
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()?
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)