微调
This commit is contained in:
@@ -226,6 +226,7 @@ function getArticlesByPosition($postion)
|
|||||||
* @Date: 2021/12/1 13:28
|
* @Date: 2021/12/1 13:28
|
||||||
* @param $category_id
|
* @param $category_id
|
||||||
* @param int $take
|
* @param int $take
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
|
||||||
*/
|
*/
|
||||||
function getResumesByCate($category_id, $take = 8)
|
function getResumesByCate($category_id, $take = 8)
|
||||||
{
|
{
|
||||||
@@ -236,3 +237,24 @@ function getResumesByCate($category_id, $take = 8)
|
|||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Advert;
|
use App\Models\Advert;
|
||||||
|
use App\Models\Article;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
|
|
||||||
class CategoryController extends Controller
|
class CategoryController extends Controller
|
||||||
@@ -32,11 +33,26 @@ class CategoryController extends Controller
|
|||||||
$pageCount = 100;
|
$pageCount = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
$articles = $category->relations(Category::TYPE_ARTICLE)
|
if ($category->id == 37) {
|
||||||
->where('status', 1)
|
$categories = Category::get();
|
||||||
->latest('sort')
|
$children = array_merge([$category->id], getAllChild($categories, $category->id));
|
||||||
->latest('created_at')
|
|
||||||
->paginate($pageCount);
|
$articles = Article::query()
|
||||||
|
->whereHas('categories', function ($q) use ($children) {
|
||||||
|
$q->whereIn('id', $children);
|
||||||
|
})
|
||||||
|
->where('status', 1)
|
||||||
|
->latest('sort')
|
||||||
|
->latest('created_at')
|
||||||
|
->paginate($pageCount);
|
||||||
|
} else {
|
||||||
|
$articles = $category->relations(Category::TYPE_ARTICLE)
|
||||||
|
->where('status', 1)
|
||||||
|
->latest('sort')
|
||||||
|
->latest('created_at')
|
||||||
|
->paginate($pageCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$parent = $category;
|
$parent = $category;
|
||||||
if (! $category->getChildrenCount() && $category->parent) {
|
if (! $category->getChildrenCount() && $category->parent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user