From a1e2085bcbf8471dab2a7f569d8a2853779c3e13 Mon Sep 17 00:00:00 2001 From: xuanchen <122383162@qq.com> Date: Fri, 19 Aug 2022 17:21:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/CategoryController.php | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index c5511bf..176b250 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -19,8 +19,8 @@ class CategoryController extends Controller $parent = getTopCate($category->id); $template = array_flip(config('haai.category')); - if (isset($template[$category->id]) && !in_array($category->id, config('haai.no_list'))) { - return view('category.' . $template[$category->id], compact('category', 'parent')); + if (isset($template[$category->id]) && ! in_array($category->id, config('haai.no_list'))) { + return view('category.'.$template[$category->id], compact('category', 'parent')); } return redirect(route('category.list', $category)); @@ -39,17 +39,17 @@ class CategoryController extends Controller } $cate_ids = Category::where('parent_id', $category->id) - ->orWhere('id', $category->id) - ->where('status', 1) - ->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]) - ->pluck('id') - ->toArray(); + ->orWhere('id', $category->id) + ->where('status', 1) + ->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]) + ->pluck('id') + ->toArray(); $articles = Article::where('status', 1) - ->ByCategory($cate_ids) - ->latest('sort') - ->latest() - ->paginate($take); + ->ByCategory($cate_ids) + ->latest('sort') + ->latest() + ->paginate($take); $parent = getTopCate($category->id); @@ -57,6 +57,10 @@ class CategoryController extends Controller $parent = $category->parent; } + if ($category->children->isEmpty()) { + $parent = $category->parent; + } + return view($template, compact('category', 'parent', 'articles')); }