1 回答
TA贡献1830条经验 获得超3个赞
这应该可以做到:
$list = Category::select('id', 'name', 'slug')
->where([
'in_menu' => 1,
'status' => 1,
'deleted_at' => null
])
->orderBy('id', 'desc')
->get();
$data = [];
foreach ($list as $category) {
$sublist = Subcategory::select('id', 'name', 'slug')
->where([
'category_id' => $category->id,
'status' => 1,
'deleted_at' => null
])
->orderBy('id', 'desc')
->get();
$item = [
"id" => $category->id,
"name" => $category->name,
"slug" => $category->slug,
"subcategory" => [],
];
foreach($sublist as $subcategory) {
$fsublist = Fsubcategory::select('id', 'name', 'slug')->where(array('subcategory_id' => $subcategory->id, 'status' => 1, 'deleted_at' => null))->orderBy('id', 'desc')->get();
$subitems = [];
foreach($fsublist as $fsubcategory) {
$subitems[] = [
"fsub_id" => $fsubcategory->id,
"fsub_name" => $fsubcategory->name,
"fsub_slug" => $fsubcategory->slug,
];
}
$item["subcategory"][] = [
"sub_id" => $subcategory->id,
"sub_name" => $subcategory->name,
"sub_slug" => $subcategory->slug,
"fsubcategory" => $subitems,
];
}
$data[] = $item;
}
return response()->json(['response' => 200, 'data' => $data]);
- 1 回答
- 0 关注
- 116 浏览
添加回答
举报