Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取模型子模型及其子模型laravel_Php_Laravel - Fatal编程技术网

Php 获取模型子模型及其子模型laravel

Php 获取模型子模型及其子模型laravel,php,laravel,Php,Laravel,有谁能告诉我如何使用eloquent在控制器中获取模型子模型及其子模型吗?我有组织模型、汽车、CarPrice、模型详细信息和汽车图像,到目前为止,我设法使用 $cars = $organization->cars()->with('model_details')->with('car_price')->with('car_images')->get(); 但我还想得到ModelDetails的子模型,比如制造商,有没有更好的方法不需要在所有汽车中循环?我已在模型

有谁能告诉我如何使用eloquent在控制器中获取模型子模型及其子模型吗?我有组织模型、汽车、CarPrice、模型详细信息和汽车图像,到目前为止,我设法使用

$cars = $organization->cars()->with('model_details')->with('car_price')->with('car_images')->get();

但我还想得到ModelDetails的子模型,比如制造商,有没有更好的方法不需要在所有汽车中循环?我已在模型中正确设置了关系。

您可以对嵌套关系使用
运算符,如下所示:

$cars = $organization->cars()
                     ->with('model_details.manufacturer')
                     ->with('car_price')
                     ->with('car_images')
                     ->get();

向下滚动到
Nested Eager Loading

当然,当我的声誉超过15岁时,我暂时无法做到:)你不需要15个声誉来接受答案。检查这个