<?php

namespace App\Jobs;

use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class SendReminderEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $user;

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

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(Mailer $mailer)
    {
        //php artisan queue:listen --sleep 1 --delay 5 --tries 3 触发
        //php artisan queue:work redis --queue=email --sleep 1 --delay 5 --tries 3
        $user = $this->user;
        $mailer->send('emails.reminder', ['user' => $user], function ($message) use ($user) {
            $message->to($user->email)->subject('新功能发布test1');
        });
    }
}
