Aug 23, 2023
0
Level 3
Got wired issue in laravel queue notification?
I have a class like this
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class TestNotification extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct(
public readonly string $name,
public readonly float $amount,
public readonly string $trekName,
public readonly string $trekDate,
) {
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['database'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'message' => "{$this->name} booked {$this->trekName} and paid {$this->amount} trek start date {$this->trekDate}"
];
}
}
when calling this notification
$user = User::find(1);
$user->notify(new TestNotification('Test', 100, 'Test Trek', '2023-10-10'));
And when I call this notification sometimes it saves only "Test" data in the notifications table and most of the time it stores data like this "Test booked Test Trek camp trek and paid 1 trek start date 2023-10-10"
If I call notification 10 times I got a "Test" 1/2 times. Why is this wired issue caused?
But this issue only happens on the server, not on the local machine.
Please or to participate in this conversation.