Laravel Distinct 查询在我的项目中不起作用

在我的 laravel 项目中,我加入了 2 个以上的表,但问题是在表中location_services,有多个具有相同 location_id 和 services_id 的条目。在这种情况下,我只想取一行。以下是我的查询。这里有什么问题。请帮助我解决它

   $loc_services = Clinic::select('*')
                        ->join('locations', 'locations.clinicID', '=', 'clinics.clinicID')
                        ->join('location_services', 'location_services.locationID', '=', 'locations.locationID')
                        ->join('services', 'services.serviceID', '=', 'location_services.serviceID')
                        ->whereIn('services.serviceID',$services_id)
                        ->where('clinics.api_key','=',$apiKey) 
                        ->get();

请帮忙。

我想从在不同位置提供各种服务的诊所表中检索所有数据。每个位置可能有也可能没有超过一项服务


HUWWW
浏览 83回答 1
1回答

隔江千里

您可以使用groupBy()方法来实现目标。get()只需在方法调用之前添加此方法。groupBy('location_services.locationID', 'location_services.serviceID')
打开App,查看更多内容
随时随地看视频慕课网APP