微调
This commit is contained in:
@@ -19,6 +19,27 @@ function getOneCategory($categoryId, $return = '')
|
|||||||
return new Category;
|
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: 获取文章分类详情
|
* Notes: 获取文章分类详情
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -45,6 +45,14 @@ class CategoryController extends Controller
|
|||||||
->latest('created_at')
|
->latest('created_at')
|
||||||
->paginate();
|
->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 {
|
} else {
|
||||||
$articles = $category->relations($category->type)
|
$articles = $category->relations($category->type)
|
||||||
->where('status', 1)
|
->where('status', 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user