我想从它的官方文档中学习laravel数据库队列。我已经完成了文档中给出的配置。Laravel 5.1没有关于排队模型的查询结果
这里我的工作:
<?php
namespace App\Jobs;
use App\SearchLog;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendTicket extends Job implements SelfHandling, ShouldQueue
{
use InteractsWithQueue, SerializesModels;
protected $log;
protected $searchLog = array();
public function __construct(SearchLog $log , $data = array())
{
$this->log = $log;
$this->searchLog = $data;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$this->log->create($this->searchLog);
}
在我的控制器我这样调用
public function store(Request $request)
{
$searchLog = array();
// searchLog contains the data to be inserted into database
$log = new SearchLog();
$this->dispatch(new SendTicket($log , $searchLog));
}
当我运行php artisan queue:listen
我得到这样
[照亮\数据库\ Eloquent \ ModelNotFoundException]没有查询 模型[App \ SearchLog]的结果。
但是,当我编辑的职位像这样
//only edited code
public function __construct($data = array())
{
$this->searchLog = $data;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
SearchLog::create($this->searchLog);
}
当从这样的
public function store(Request $request)
{
$searchLog = array();
// searchLog contains the data to be inserted into database
$this->dispatch(new SendTicket($searchLog));
}
调用它工作正常,并插入数据。
在这里,我的问题是:
- 如何将对象发送到队列中?
- 将数据发送到队列以便我们可以处理的最佳方式是什么?
这Laravel行为是意外这么多的人,所以我很高兴地看到,有是一个相关的错误报告在这里:https://github.com/laravel/framework/issues/14526 – Ryan