我正在尝试在早期有效查询中获取带有where条件的记录。这是我的关系方法。
public function OrdersReferrals()
{
return $this->hasMany('App\Order', 'referred_by');
}
public function referrals()
{
return $this->hasMany('App\User', 'referred_by')->with('referrals', 'OrdersReferrals');
}
下面是我的控制器查询
$userData = User::with('adminuserrreferrals')
->where('id', $id)
->where('payout_status', 'pending')
->get();
问题是这个查询,where条件只适用于用户表。而我需要这个订单表的->where('payout_status','pending')
。
发布于 2020-07-03 19:35:36
你的问题不是很清楚,但我认为你想要这样的东西(过滤orders
表中的payout_status
字段):
$userData = User::with('adminuserrreferrals')
->whereHas(['adminuserrreferrals' => function($query) {
$query->where('payout_status', 'pending');
}])
->where('id', $id)
->get();
我希望ordsrs
表的adminuserrreferrals
关系方法在User
模型中定义正确,并且存在Order
模型。
https://stackoverflow.com/questions/62718058
复制相似问题