From ba5abed3423ece291478bcc27f3c86f25d1558ef Mon Sep 17 00:00:00 2001 From: xuanchen <122383162@qq.com> Date: Fri, 29 Oct 2021 16:57:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=A2=9E=E5=8A=A0=E8=B7=B3?= =?UTF-8?q?=E8=BD=ACurl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Category/IndexController.php | 6 ++++ app/Http/Controllers/CategoryController.php | 33 +++++++++++-------- app/Models/Category.php | 2 ++ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/app/Admin/Controllers/Category/IndexController.php b/app/Admin/Controllers/Category/IndexController.php index 620482b..ceba1ab 100644 --- a/app/Admin/Controllers/Category/IndexController.php +++ b/app/Admin/Controllers/Category/IndexController.php @@ -43,6 +43,9 @@ class IndexController extends AdminController })->pluck('title', 'id'); })->help('当分类类型是文章详情的时候需要选择关联文章'); }) + ->when('web', function (WidgetForm $form) { + $form->text('url', '跳转链接'); + }) ->required(); $form->textarea('description', '分类简介') @@ -107,6 +110,9 @@ class IndexController extends AdminController })->pluck('title', 'id'); })->help('当分类类型是文章详情的时候需要选择关联文章'); }) + ->when('web', function (Form $form) { + $form->text('url', '跳转链接'); + }) ->required(); $form->textarea('description', '分类简介')->rows(4)->rules('nullable'); diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 0e5fc85..8cb7f95 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -11,23 +11,28 @@ class CategoryController extends Controller //显示分类 public function show(Category $category) { - if ($category->type == Category::TYPE_SHOW) { - if ($category->relations) { - return redirect(route('article.show', $category->relations)); - } + switch ($category->type) { + case Category::TYPE_WEB: + return redirect()->to($category->url); + break; + case Category::TYPE_SHOW: + if ($category->relations) { + return redirect(route('article.show', $category->relations)); + } - return redirect('/'); + return redirect('/'); + break; + default: + $articles = Article::where('category_id', $category->id) + ->latest('sort') + ->latest() + ->paginate(); + + $parent = $category->getTop(); + + return view('category.show', compact('category', 'parent', 'articles')); } - $articles = Article::where('category_id', $category->id) - ->latest('sort') - ->latest() - ->paginate(); - - $parent = $category->getTop(); - - return view('category.show', compact('category', 'parent', 'articles')); - } } diff --git a/app/Models/Category.php b/app/Models/Category.php index be70dae..909dc66 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -15,10 +15,12 @@ class Category extends Model public const TYPE_SHOW = 'show'; public const TYPE_ARTICLE = 'article'; public const TYPE_ADVERT = 'advert'; + public const TYPE_WEB = 'web'; public const TYPES = [ self::TYPE_ARTICLE => '文章列表', self::TYPE_SHOW => '文章详情', self::TYPE_ADVERT => '图片', + self::TYPE_WEB => '跳转链接', ]; public function getLinkAttribute()