首页 文章

在Queues Laravel上运行任务调度程序

提问于
浏览
0

//邮件验证文件

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);
    }
}

我目前正致力于这个简单的laravel项目 . 我尝试使用队列来实现用户电子邮件激活功能 . 当我使用 php artisan queue:work 来运行它时,它工作正常 . 我现在尝试创建一个任务调度程序,每五分钟执行一次

//代码在这里

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

但它返回未定义的变量 . 上面有错误,还是有更好的方法让队列自动运行?

1 回答

相关问题