我正在尝试使用命令链式发送 3 封邮件withChain
,所以基本上我发送第一封邮件,1 分钟后使用该delay()
功能发送另一封邮件,1 分钟后再次发送第三封邮件。在文档中,他们谈论延迟和链接,但不是同时谈论它们中的两个。可能吗 ?
我收到一个错误:
函数 App\Jobs\SendEmail::__construct() 的参数太少,在第 139 行的 /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Foundation/Bus/PendingChain.php 中传递了 0,而预期为 1
但我不知道为什么,因为我正在传递论点......
作业控制器.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
use App\Jobs\SendEmail;
use App\Http\Controllers\Controller;
class JobController extends Controller
{
/**
*
*
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function enqueue(Request $request)
{
$details = ['email' => 'contact@uh-lawyers.fr'];
SendEmail::withChain([
new SendEmail($details),
new SendEmail($details)
])->dispatch();
}
}
发送电子邮件.php:
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Mail\NewUserNotification;
use Illuminate\Support\Facades\Mail;
class SendEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $details;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($details)
{
$this->details = $details;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$email = new NewUserNotification();
Mail::to($this->details['email'])->send($email);
}
}
新用户通知.php:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NewUserNotification extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('contact@uh-lawyers.fr', 'UH-Group')
->subject('Mailtrap Confirmation')
->markdown('mails.exmpl')
->with([
'name' => 'New Mailtrap User',
'link' => '/inboxes/'
]);
}
}
谢谢。