A
A
afal992022-02-06 22:45:37
Laravel
afal99, 2022-02-06 22:45:37

Why are notifications not being sent in Laravel 8?

Through the facade I send notifications with a delay

foreach ($orders as $i => $order)
{
    Notification::send($order, (new OrdersDelivered($text_template))
        ->delay(now()->addSeconds($i * 30))
    );
}


The notification itself looks like this
class OrdersDelivered extends Notification implements ShouldQueue
{
    use Queueable;

    private string $text;

    public function __construct($text)
    {
        $this->text = $text;
    }

    public function via($notifiable): array
    {
        return [WhatsappChannel::class];
    }

    public function toWhatsapp($notifiable): WhatsappMessage
    {
        return (new WhatsappMessage())
            ->to($notifiable->client_phone)
            ->text($this->text)
            ->totalOrders($notifiable->total);
    }
}


I made my own channel for sending
class WhatsappChannel
{
    public function send(mixed $notifiable, Notification $notification)
    {
        $message = $notification->toWhatsapp($notifiable);
        WhatsappApi::send($message);
    }
}


All of this works fine as long as you don't use a queue and write implements ShouldQueue. I need to use a queue, but when the handler pulls out tasks, the send method on the channel is not even called. At the same time, all tasks get into the queue6200250f4c17b394092915.png
6200254d3374f313435916.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2022-02-10
@v__V__v

Most likely, you need to start the queue handler, the queue itself does nothing, you need to execute the command
php artisan queue:work
or
php artisan queue:listen
Note that the handler, according to the documentation, must be launched before sending notifications to the queue!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question