【问题标题】:Query builder in a queued command in Laravel 5Laravel 5中排队命令中的查询构建器
【发布时间】:2015-08-31 17:51:58
【问题描述】:

我正在使用 Laravel 5.0,并使用 Artisan CLI 创建了一个排队命令:

php artisan make:command SendEmail --queued

我需要在此命令中使用 DB::table() 查询构建器方法,但我无法使其工作。

这是我的代码的摘录:

<?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
}

}

我做错了什么?

【问题讨论】:

    标签: laravel-5 queue query-builder


    【解决方案1】:

    我发现了错误。我必须重新启动主管队列才能正确重新读取代码:

    supervisorctl
    supervisor> restart myQueue
    

    【讨论】:

      猜你喜欢
      • 2015-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多