创建
php artisan make:job name
php artisan queue:restart
php artisan queue:work
php artisan queue:listen
php artisan queue:work --daemon
你的方法
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
class Checkout implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct()
{
}
public function handle()
{
Mail::send(
'welcome',
['name'=>'233'],
function($message){
$to = '111@qq.com';
$message ->to($to)->subject('邮件测试');
});
}
}
调用
$job=new Checkout();
$this->dispatch($job);