【发布时间】: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