I am creating an API with Laravel and want to send a push notification using the Laravel notification system. I have a model for matches (basically this message), another user might like this match. When the match is pleasant, the creator of the message will receive a push notification. This is exactly the same as Instagram, Facebook, etc.
Often a push notification was not sent to the user. I installed Laravel Horizon to see if there are any errors. Sometimes a notification was sent, and sometimes not. With the same data:

A notification is sometimes interrupted with the same data (same user, same).
The error is as follows:
Illuminate\Database\Eloquent\ModelNotFoundException: [App\Models\Match] 118 /home/forge/owowgolf.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:312
, , . - , ? , , , . , , , . - /.
:
public function show(Match $match)
{
$match->like();
$players = $match->players()->where('user_id', '!=', currentUser()->id)->get();
foreach ($players as $user) {
$user->notify(new NewLikeOnPost($match, currentUser()));
}
return ok();
}
:
<?php
namespace App\Notifications;
use App\Models\Match;
use App\Models\User;
use Illuminate\Bus\Queueable;
use NotificationChannels\Apn\ApnChannel;
use NotificationChannels\Apn\ApnMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
class NewLikeOnPost extends Notification implements ShouldQueue
{
use Queueable;
private $match;
private $user;
public function __construct(Match $match, User $user)
{
$this->user = $user;
$this->match = $match;
$this->onQueue('high');
}
public function via($notifiable)
{
if ($notifiable->wantsPushNotification($this)) {
return ['database', ApnChannel::class];
}
return ['database'];
}
public function toApn($notifiable)
{
return ApnMessage::create()
->badge($notifiable->unreadNotifications()->count())
->sound('success')
->body($this->user->username . ' flagged your match.');
}
public function toArray($notifiable)
{
return [
'user_id' => $this->user->id,
'body' => "<flag>Flagged</flag> your match.",
'link' => route('matches.show', $this->match),
'match_id' => $this->match->id,
];
}
public function getMatch()
{
return $this->match;
}
}