我之前编写的没有参数的作业现在需要它们。它旨在使用 Mail 类发送电子邮件。我现在需要使用参数执行此作业,但队列没有看到它们。我想知道我是否以错误的方式初始化 SendMailFinished 但应该没问题。我已经读到序列化存在问题,但我在 SendMailFinished 中添加了受保护的变量。class ReporteBCH implements ShouldQueue{ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. * No hay que pasar ninguna variable. * @return void */ public function __construct() { // } /** * Busca todos los equipos del inventario, luego revisa el SCCM con sus relaciones y el bginfo * * @return void */ public function handle() { $msg = 'Proceso terminado. Ver ' . url(''); $subj = 'Proceso BCH'; $mailto = env('MAIL_TO'); $send = new SendMailFinished($msg, $subj, $mailto); $send->dispatch(); }}现在的问题是,当我从控制台启动它时,该过程失败了,因为它看不到参数,就好像我没有在构造函数中添加它们一样。SendMailFinished 看起来像这样:class SendMailFinished implements ShouldQueue{ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. * * @return void */ public $tries = 3; protected $msg; protected $subj; protected $mailto; public function __construct($msg, $subj, $mailto) { // $this->msg = $msg; $this->subj = $subj; $this->mailto = $mailto; } /** * Execute the job. * * @return void */ public function handle() { //Envia correo cuando termine cola. Mail::to($this->mailto)->queue(new TasksFinished($this->msg, $this->subj)); }}错误如下:Symfony\Component\Debug\Exception\FatalThrowableError: Too few arguments to function App\Jobs\SendMailFinished::__construct(), 0 passed in C:\laragon\www\reportes\vendor\laravel\framework\src\Illuminate\Foundation\Bus\Dispatchable.php on line 26 and exactly 3 expected in C:\laragon\www\reportes\app\Jobs\SendMailFinished.php:31我已经阅读了https://laravel.com/docs/5.8/queues#creating-jobs ,但对它了解不多,还有这个如何将参数发送到队列?
- 2 回答
- 0 关注
- 201 浏览
添加回答
举报
0/150
提交
取消