我想從它的官方文檔中學習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