3

我想在 Laravel eloquent 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->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_order

4

0 回答 0