我 Build 一个寄存器候选系统,我使用事件:UserRegistered和2个侦听器:句柄侦听器中的SendConfirmation.php和AssignRole.php SendConfirmation.php

public function handle(UserRegistered $event)
{
    SendConfirmationEmailJob::dispatch($event->user);
}

在工作班我有 SendConfirmationEmailJob.php

class SendConfirmationEmailJob implements ShouldQueue {

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
 * The number of times the job may be attempted.
 */
public $tries = 5;

/**
 * The number of seconds the job can run before timing out.
 */
public $timeout = 60;


protected $user;

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

/**
 * Execute the job.
 */
public function handle()
{   
   // DOESN'T WORK AND JOB FAILED
    $email = $this->user->email;
    Mail::to($email)->send(new VerifyEmail());
}

public function failed(Exception $exception)
{
    Log::info("Failed job", ['user.failed' => $exception]);
}

}

当用户注册时我尝试发送电子邮件排队,用

php工匠队列:工作

工作失败,但如果做这样小的改变,工作流程工作得很好保护$ email;

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

/**
 * Execute the job.
 */
public function handle()
{   
   // WORK FINE
    $email = $this->email;
    Mail::to($email)->send(new VerifyEmail());
}

所以我不明白为什么我的工作在分配时失败了

$ email = $ this-> user-> email;