Maxwell
Maxwell

Reputation: 151

Running Task scheduler on Queues Laravel

//Mail Verification File

class EmailVerification extends Mailable
{

    use Queueable, SerializesModels;

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

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('frontend.email.activation')->with([
            'email_token' => $this->user->email_token,
        ]);
    }
}

//SendVerificationEmail

class SendVerificationEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    protected $user;
    public function __construct($user)
    {
        $this->user = $user;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $email = new EmailVerification($this->user);
        Mail::to($this->user->email)->send($email);
    }
}

i am currently working on this simple laravel projects. I am try to make use of queues to implement the user email activation function. and it works fine when i use php artisan queue:work to run it. i now tried to create an task scheduler to do this every five minutes

// The code Here

protected function schedule(Schedule $schedule)
{
    $schedule->job(new SendVerificationEmail($user))->everyFiveMinutes();
}

But its returning undefined variable. Is there a mistake in the above, or is there a better way to make Queues run automatically?

Upvotes: 0

Views: 1628

Answers (1)

Mavin
Mavin

Reputation: 64

Please read: Laravel 5.5 Documentation - Queues#dispatching-jobs

You can't schedule this kind of job, you should dispatch it.

Upvotes: 0

Related Questions