【发布时间】:2017-10-26 23:59:09
【问题描述】:
//邮件验证文件
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,
]);
}
}
//发送验证邮件
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();
}
但它返回未定义的变量。上面有没有错误,或者有没有更好的方法让Queues自动运行?
【问题讨论】: