5.1 window下没有存入jobs表中,评论区也有朋友是这样的问题,使用了他们的方法没有解决,仔细寻找了多遍仍没有解决,贴上代码站长帮忙看看!
使用php artisan make:job SendReminderEmail --queued 生成的SendReminderEmail类,其中代码编辑如下:
···
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\User;
use Log;
class SendReminderEmail 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()
{
Log::info('The email from'.$this->user->name);
}
}
···
controller中的代码如下:
···
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\jobs\sendReminderEmail;
use App\User;
class QueueController extends Controller
{
public function store () {
$users = User::where('id', '>', 6)->get();
foreach ($users as $user) {
$this->dispatch(new sendReminderEmail($user));
}
return 'Success.';
}
}
···
运行结果页面显示success成功了,但队列仍然是同步执行的,在log中同步生成了几条信息
*[2017-09-09 02:42:31] local.INFO: The email fromProf. Wayne Douglas
*[2017-09-09 02:42:31] local.INFO: The email fromAnsley West
*[2017-09-09 02:42:31] local.INFO: The email fromDashawn Dare DVM
*[2017-09-09 02:42:31] local.INFO: The email fromDr. Yvette Okuneva I
*[2017-09-09 02:42:31] local.INFO: The email fromAmelia Nienow
*[2017-09-09 02:42:31] local.INFO: The email fromMiss Myrtle Ruecker
*[2017-09-09 02:42:31] local.INFO: The email fromMartina Jacobs