我有两个表用户和付款用户表如下:id
fisrtname
lastname付款表如下:id
users_id
receiver_id注意:用户表也是接收者表。我想要获得已付款但未收到任何付款的用户列表
1 回答
萧十郎
TA贡献1815条经验 获得超13个赞
请尝试我的解决方案:
class User extends Authenticatable {
...
public function payments()
{
return $this->hasMany(Payment::class, 'users_id');
}
}
$users = \App\User::query()->getModel();
$users = $users->whereHas('payments', function ($query) {
/** @var Builder $query */
$query->havingRaw('COUNT(*) = 1');
})->whereNotExists(function ($query) {
/** @var Builder $query */
$query->select(['receiver_id'])
->from('payments')
->whereRaw('users.id = payments.receiver_id');
})->get();
- 1 回答
- 0 关注
- 113 浏览
添加回答
举报
0/150
提交
取消