jeudi 30 mars 2017

Queue mails through Laravel 5 scheduler

I have a scheduler set up to run every minutes:

$schedule->command('reminder_upcoming_tasks')
         ->everyMinute();

Which is suppose to queue an email:

Mail::to($user->email)
    ->queue(new ReminderUpcomingTasksMail($user));

Unfortunately this doesn't work but using notification instead works:

Notification::send($user, new ReminderUpcomingTasksNotification($user));

So I know that my scheduler works and is properly triggered.

And my Mail looks like this:

<?php

namespace App\Mail;

use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class ReminderUpcomingTasksMail extends Mailable
{
    use Queueable, SerializesModels;

    protected $user;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(User $user)
    {
        $this->user               = $user;
        $this->onQueue('default');
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.reminder_upcoming_tasks')
            ->with([
                'user'               => $this->user,
            ])
            ->subject("Your daily summary");
    }
}

If I test this mail in a controller without queue, this also works:

Mail::to($user->email)
    ->send(new ReminderUpcomingTasksMail($user));

Any idea of what's missing?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire