2015-08-31 43 views
0

我使用Laravel 5.0和我已經創建與工匠CLI排隊命令:查詢生成器在Laravel排隊命令5

php artisan make:command SendEmail --queued 

我需要使用DB ::表()查詢生成器方法放入此命令中,但我無法使其工作。

這是我的代碼的摘錄:

<?php namespace App\Commands; 

use App\Commands\Command; 
use DB; 

use Illuminate\Queue\SerializesModels; 
use Illuminate\Queue\InteractsWithQueue; 
use Illuminate\Contracts\Bus\SelfHandling; 
use Illuminate\Contracts\Queue\ShouldBeQueued; 

class SendEmail extends Command implements SelfHandling, ShouldBeQueued { 

use InteractsWithQueue, SerializesModels; 

protected $message; 

public function __construct($message) 
{ 
    $this->message = $message; 
} 

public function handle() 
{ 
    $data = DB::table('structures')->where('id', '=', '1')->first(); 
    // $data is always empty even if database connection works outside the command!!! <------------------- 
    // no error exception is thrown 
} 

} 

我在做什麼錯?

回答

0

我發現了錯誤。我不得不重新啓動監督員隊列以便代碼被正確地重新讀取:

supervisorctl 
supervisor> restart myQueue