This commit is contained in:
2022-08-19 20:00:15 +08:00
parent 526c433ed6
commit 486db5a1ab
2 changed files with 29 additions and 0 deletions

View File

@@ -19,6 +19,27 @@ function getOneCategory($categoryId, $return = '')
return new Category;
}
/**
* Notes: 获取所有下级
*
* @Author: 玄尘
* @Date: 2022/8/19 17:24
* @param $array
* @param $categoryId
* @return array
*/
function getAllChild($categories, $categoryId)
{
$arr = array();
foreach ($categories as $category) {
if ($category['parent_id'] == $categoryId) {
$arr[] = $category['id'];
$arr = array_merge($arr, getAllChild($categories, $category['id']));
};
};
return $arr;
}
/**
* Notes: 获取文章分类详情
*

View File

@@ -45,6 +45,14 @@ class CategoryController extends Controller
->latest('created_at')
->paginate();
} elseif ($category->id == 7) {
$categories = Category::get();
$children = array_merge([$category->id], getAllChild($categories, $category->id));
$articles = Article::ByCategory($children)
->where('status', 1)
->latest('sort')
->latest('created_at')
->paginate();
} else {
$articles = $category->relations($category->type)
->where('status', 1)