我正在使用Laravel 5.4,我想在发送电子邮件中实现队列。我具有注册为
的功能public function register(CustomerRequest $request)
{
\Log::info("Request Cycle with Queues Begins");
$parameter = 'This is parameter';
dispatch(new SendWelcomeEmail($parameter));
\Log::info("Request Cycle with Queues Ends");
}
并且我在App\Jobs\SendWelcomeEmail
内创建了一个工作。如下所示:
class SendWelcomeEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $parameter;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($parameter)
{
$this->parameter = $parameter;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Log::info($this->parameter);
}
}
为什么会出现类似错误
Type error: Too few arguments to function App\Jobs\SendWelcomeEmail::handle(), 0 passed and exactly 1 expected in
答案 0 :(得分:0)
$parameter
不是用于handle()
方法,而是用于其构造函数
class SendWelcomeEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $parameter;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($parameter)
{
$this->parameter = $parameter;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Log::info($this->parameter);
}
}