我有两张桌子
提供者和User_Requests
我只需要获得已取消两个或更多请求的提供商
Providers.php
public function trips() {
return $this->hasMany('App\UserRequests');
}
UserRequests.php
public function provider()
{
return $this->belongsTo('App\Provider');
}
如何才能获得有2个以上取消请求的提供商?
user_requests表包含以下列:
provider_id, status
where status => enum =('SEARCHING','CANCELED','ACCEPTED')
谢谢!
我想你可以用:
$userRequests = UserRequests::where('status','CANCELLED')
->groupBy('provider_id')
->havingRaw('COUNT(*) >= 2')
->with('provider')
->get();