Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.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

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_Laravel 5 - Fatal编程技术网

Php 数组的雄辩分组-Laravel

Php 数组的雄辩分组-Laravel,php,laravel,laravel-5,Php,Laravel,Laravel 5,我在laravel中正确设置了我的模型和关系,我可以使用下面的代码检索数据 $restaurants = Restaurant::with('restaurantClass', 'city', 'location', 'menuCategories', 'menuItems', 'menuModifierGroups', 'menuModifierItems')->where(['id' => $id])->get(); 餐厅属于“餐厅类别”、“城市”、“位置” 餐厅有许多“

我在
laravel
中正确设置了我的模型和关系,我可以使用下面的代码检索数据

$restaurants = Restaurant::with('restaurantClass', 'city', 'location', 'menuCategories', 'menuItems', 'menuModifierGroups', 'menuModifierItems')->where(['id' => $id])->get();
餐厅
属于
“餐厅类别”、“城市”、“位置”

餐厅
有许多
“菜单类别”、“菜单项”、“菜单修改器组”、“菜单修改器项”

我得到我的
数据
如下

[
  {
    // restaurant details here,
    "restaurant_class": {},
    "city": {},
    "location": {},
    "menu_categories": [],
    "menu_items": [],
    "menu_modifier_groups": [],
    "menu_modifier_items": []
  }
]
菜单\u类别
有许多
“菜单项”、“菜单修改器组”、“菜单修改器项”

如何按
菜单\u类别对它们进行分组?

所以基本上是对内部数组进行分组。

你指的是按菜单类别对内部数组进行分组。
菜单类别对内部数组进行分组。菜单类别对内部数组进行分组。是的,但分组是什么?餐厅还是您想将所有菜单项、菜单修改器组和菜单修改器项分组在菜单类别下?是的,在
menu\u类别下
whereHas()
e.g.
Restaurant::with('restaurantClass',..)->whereHas([“menu\u categories”=>function($query){/*尝试在此处进行分组*/})->get()
?-不知道它们是否有可能。你指的是按菜单类别分组
“菜单项”、“菜单修改器组”、“菜单修改器项”
,还是指按菜单类别分组
,还是按菜单类别分组?是的,但分组什么?餐厅还是要所有菜单项,菜单修改器在菜单类别下分组的组和菜单修改器项?是的,在
菜单类别下
你看过
whereHas()
例如
Restaurant::with('restaurantClass',..)->whereHas([“菜单类别”=>函数($query){/*尝试在这里分组*/})->get();
?-不知道这是否可行