有人能告诉我如何使用雄辩的方法在控制器中获取模型子模型及其子模型吗?我有组织模型,汽车,CarPrice,ModelDetails和汽车图像,到目前为止,我成功地获得了所有的数据
$cars = $organization->cars()->with('model_details')->with('car_price')->with('car_images')->get();但我也想得到ModelDetails的子型号,例如,制造商,有什么更好的方法来做到这一点,而不循环通过所有的汽车?我在模特儿里建立了恰当的关系。
发布于 2016-11-28 16:02:41
可以将.运算符用于嵌套关系,如下所示:
$cars = $organization->cars()
->with('model_details.manufacturer')
->with('car_price')
->with('car_images')
->get();文档向下滚动到Nested Eager Loading
https://stackoverflow.com/questions/40848365
复制相似问题