当我在laravel模型中定义表名时
class Test extends Model
{
use SoftDeletes;
protected $table="en_test";
并输入我的代码
DB::enableQueryLog();
Test::get();
dd(DB::getQueryLog());
我的成绩不佳
"query" => "select * from `en_test` where `en_test`.`deleted_at` is null"
"bindings" => []
"time" => 0.88
但是当我将表名设置为 受保护的$ table;
class Test extends Model
{
use SoftDeletes;
public function __construct()
{
$locale =\App::getLocale();
$this->table=$locale."_test";
}
并编写以前的代码。我有
"query" => "select * from `en_test`"
"bindings" => []
"time" => 0.93
为什么从我的查询中删除了where
fa_test .
deleted_at is null
?
答案 0 :(得分:2)
这是因为您在构造函数中使用了自定义代码,并且尚未在此处启动父构造函数,因此未引导特征。您应该使用:
public function __construct()
{
$locale =\App::getLocale();
$this->table=$locale."_test";
parent::_construct();
}
启动父级构造函数。