Php 模型中具有动态表名的Laravel Eloquent联接
我想在Laravel Elount Orm中运行此查询Php 模型中具有动态表名的Laravel Eloquent联接,php,laravel-5,laravel-eloquent,Php,Laravel 5,Laravel Eloquent,我想在Laravel Elount Orm中运行此查询 "SELECT a.* from $tbl1 a, $tbl2 b Where a.user_id = b.user_id and a.order_id = 1"; 此外,我的$tbl1名称是动态的,变量$a将根据需求进行更改 $a = 'user'; $tbl1 = $a . '_order'; 现在我有两个模型,像 Class AB{ public function b(){ return $this->hasOn
"SELECT a.* from $tbl1 a, $tbl2 b Where a.user_id = b.user_id and a.order_id = 1";
此外,我的$tbl1
名称是动态的,变量$a将根据需求进行更改
$a = 'user';
$tbl1 = $a . '_order';
现在我有两个模型,像
Class AB{
public function b(){
return $this->hasOne('B','user_id');
}
}
Class B{
protected $table = 'user';
public function ab(){
return $this->belongsTo('AB','user_id');
}
}
我的控制器
Class AController{
public function hello($tbl){
$a= new AB;
$a->setTable($tbl);
$where = ['order_id' => 1];
$query = $a->with('b')->where($where)->get();
}
}
但是它返回AB模型表名abs
,因为模型名是AB,但预期的表名将是user\u order