{
$count = $this->withJoin(["user", "coupon"])->where($condition)->count();
$data = $this->withJoin(["user", "coupon"])->where($condition)->order('order.id', 'DESC')->paginate($size);
return [
"count" => $count,
"data" => $data->items()
];
}
public function user()
{
return $this->hasOne(User::class, "uid", "uid")
->bind(["phone", "nickname"])->joinType("LEFT");
}
public function coupon()
{
return $this->hasOne(Coupon::class, "id", "goods_id")
->bind(["product_name"])->joinType("LEFT");
}
使用bind()绑定字段时,如果两个模型字段名相同要怎么处理呢,就像上面的代码里两个模型都有phone字段,这时绑定就报错,提示phone字段已存在
最佳答案