<code>php artisan make:job SendEmail --queued </code>
生成后 在App\Jobs
<code><?php namespace App\Jobs; use App\User; use App\Jobs\Job; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Bus\SelfHandling; use Illuminate\Contracts\Queue\ShouldQueue; class SendEmail extends Job implements SelfHandling, ShouldQueue { use InteractsWithQueue, SerializesModels; protected $user; /** * Create a new job instance. * * @return void */ public function __construct(User $user) { $this->user = $user; } /** * Execute the job. * * @return void */ public function handle(Mailer $mailer,$email) { $mailer->send('emails.reminder', ['user' => $this->user], function ($m){ $m->to($email, 'zan')->subject('发送成功'); }); } } </code>
在控制器里这么用;
<code> $email = "onm@163.com"; $job = (new SendEmail($user,$email))->delay(260); $this->dispatch($job); </code>
在这里 传email 到 handle方法里面;
可handle 方法里 根本获取不到 $email 这个变量
Jobs 队列处理 如何传入更多数据呢 在控制器里传入
求大神指导一下呀
<code>php artisan make:job SendEmail --queued </code>
生成后 在App\Jobs
<code><?php namespace App\Jobs; use App\User; use App\Jobs\Job; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Bus\SelfHandling; use Illuminate\Contracts\Queue\ShouldQueue; class SendEmail extends Job implements SelfHandling, ShouldQueue { use InteractsWithQueue, SerializesModels; protected $user; /** * Create a new job instance. * * @return void */ public function __construct(User $user) { $this->user = $user; } /** * Execute the job. * * @return void */ public function handle(Mailer $mailer,$email) { $mailer->send('emails.reminder', ['user' => $this->user], function ($m){ $m->to($email, 'zan')->subject('发送成功'); }); } } </code>
在控制器里这么用;
<code> $email = "onm@163.com"; $job = (new SendEmail($user,$email))->delay(260); $this->dispatch($job); </code>
在这里 传email 到 handle方法里面;
可handle 方法里 根本获取不到 $email 这个变量
Jobs 队列处理 如何传入更多数据呢 在控制器里传入
求大神指导一下呀
<code>php</code><code>$mailer->send('emails.reminder', ['user' => $this->user], function ($m) use($email){ $m->to($email, 'zan')->subject('发送成功'); }); </code>