模特关系..。公寓有很多平面图。公寓里有很多照片。平面图有很多FloorplanImage。
我想要所有的公寓都有一个有0间卧室的平面图。另外,我想抓取相关的照片,和相关的FloorplanImage。
我有点没用的密码..。
$apartmentsWithStudios = Floorplan::with(['apartment', 'floorplanImage'])
->where('bedrooms', '=', 0)->get();如何从查询楼盘模型中获取公寓和所有相关模型?有可能吗?
发布于 2015-11-21 12:58:57
whereHas + with
Apartment::whereHas('floorplans', function ($floorplans) {
/** @var \Illuminate\Database\Eloquent\Query */
$floorplans->where('bedrooms', 0);
})
// with all floorplans and their images
->with('photo', 'floorplans.floorplanImage')
// OR with floorplans without bedrooms and their images
->with(['phooto', 'floorplans' => function ($floorplans) {
$floorplans->where('bedrooms', 0);
}, 'floorplans.floorplanImage'])
->get();https://stackoverflow.com/questions/33834941
复制相似问题