From 11ae4149d184dae67f98a02b578c7e0f053e3b0d Mon Sep 17 00:00:00 2001 From: Jason <506907958@qq.com> Date: Tue, 15 Oct 2019 11:48:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BF=AE=E6=94=B9=E5=B7=B2?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=9A=84=E6=A0=87=E7=AD=BE=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=20=E5=85=B3=E9=94=AE=E5=AD=97?= =?UTF-8?q?=E5=92=8C=E6=8F=8F=E8=BF=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 今天发现百度收录网址中,非常多的底栏内容,发现全是标签页面,页面内没有相关关键词和描述。今天有时间添加上 --- app/Http/Controllers/Admin/TagController.php | 2 +- app/Http/Controllers/Home/IndexController.php | 9 ++-- app/Models/Tag.php | 2 + .../2017_07_11_225347_create_tags_table.php | 5 ++- database/seeds/TagsTableSeeder.php | 42 +++++++++++-------- resources/views/admin/tag/create.blade.php | 12 ++++++ resources/views/admin/tag/edit.blade.php | 12 ++++++ resources/views/admin/tag/index.blade.php | 4 +- 8 files changed, 63 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/Admin/TagController.php b/app/Http/Controllers/Admin/TagController.php index e70185cd..3c67b28a 100644 --- a/app/Http/Controllers/Admin/TagController.php +++ b/app/Http/Controllers/Admin/TagController.php @@ -41,7 +41,7 @@ public function create() */ public function store(Store $request) { - $tag = Tag::create($request->only('name')); + $tag = Tag::create($request->only('name', 'keywords', 'description')); if ($request->ajax()) { return response()->json($tag); diff --git a/app/Http/Controllers/Home/IndexController.php b/app/Http/Controllers/Home/IndexController.php index 9307fdd8..5ecad214 100644 --- a/app/Http/Controllers/Home/IndexController.php +++ b/app/Http/Controllers/Home/IndexController.php @@ -153,13 +153,14 @@ public function category($id) * 获取标签下的文章 * * @param $id + * @update 2019年10月15日 11:27:03 by jason * * @return \Illuminate\Contracts\View\Factory */ public function tag($id) { - // 获取标签 - $tag = Tag::select('id', 'name')->where('id', $id)->first(); + // 获取标签 以及关键字 + $tag = Tag::select('id', 'name', 'keywords', 'description')->where('id', $id)->first(); if ($tag === null) { return abort(404); } @@ -171,8 +172,8 @@ public function tag($id) ->paginate(10); $head = [ 'title' => $tag->name, - 'keywords' => '', - 'description' => '', + 'keywords' => $tag -> keywords ?? '', + 'description' => $tag -> description ?? '', ]; $assign = [ 'category_id' => 'index', diff --git a/app/Models/Tag.php b/app/Models/Tag.php index faf533cc..93008755 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -11,6 +11,8 @@ * @property int $id 标签主键 * @property string $name 标签名 * @property string $slug slug + * @property string $keywords 标签关键词 + * @property string $description 标签描述主要是 SEO * * @author hanmeimei */ diff --git a/database/migrations/2017_07_11_225347_create_tags_table.php b/database/migrations/2017_07_11_225347_create_tags_table.php index ec6340d7..ae4f02cd 100644 --- a/database/migrations/2017_07_11_225347_create_tags_table.php +++ b/database/migrations/2017_07_11_225347_create_tags_table.php @@ -7,7 +7,8 @@ class CreateTagsTable extends Migration { /** * Run the migrations. - * + * @update 2019年10月15日 11:28:45 by jason + * @desc 添加 标签的关键字和描述。 * @return void */ public function up() @@ -16,6 +17,8 @@ public function up() $table->increments('id')->comment('标签主键'); $table->string('name', 20)->default('')->comment('标签名'); $table->string('slug')->default('')->comment('slug'); + $table->string('keywords')->default('')->comment('标签的关键字'); + $table->string('description')->default('')->comment('标签的描述'); $table->timestamps(); $table->softDeletes(); }); diff --git a/database/seeds/TagsTableSeeder.php b/database/seeds/TagsTableSeeder.php index 69c90931..1e5b8eda 100644 --- a/database/seeds/TagsTableSeeder.php +++ b/database/seeds/TagsTableSeeder.php @@ -14,28 +14,34 @@ public function run() DB::table('tags')->truncate(); DB::table('tags')->insert([ [ - 'id' => 1, - 'name' => 'laravel', - 'slug' => 'laravel', - 'created_at' => '2017-7-16 07:35:12', - 'updated_at' => '2016-7-16 07:35:12', - 'deleted_at' => null, + 'id' => 1, + 'name' => 'laravel', + 'slug' => 'laravel', + 'keywords' => 'laravel', + 'description' => 'Laravel是一套简洁、优雅的PHP Web开发框架(PHP Web Framework)。它可以让你从面条一样杂乱的代码中解脱出来;它可以帮你构建一个完美的网络APP,而且每行代码都可以简洁、富于表达力。', + 'created_at' => '2017-7-16 07:35:12', + 'updated_at' => '2016-7-16 07:35:12', + 'deleted_at' => null, ], [ - 'id' => 2, - 'name' => 'test', - 'slug' => 'test', - 'created_at' => '2019-01-04 15:35:12', - 'updated_at' => '2019-01-04 15:35:12', - 'deleted_at' => null, + 'id' => 2, + 'name' => 'test', + 'slug' => 'test', + 'keywords' => 'test', + 'description' => '测试描述', + 'created_at' => '2019-01-04 15:35:12', + 'updated_at' => '2019-01-04 15:35:12', + 'deleted_at' => null, ], [ - 'id' => 3, - 'name' => '已删除', - 'slug' => 'deleted', - 'created_at' => '2019-01-04 15:35:12', - 'updated_at' => '2019-01-04 15:35:12', - 'deleted_at' => '2019-01-04 15:35:12', + 'id' => 3, + 'name' => '已删除', + 'slug' => 'deleted', + 'keywords' => 'delete', + 'description' => '删除的标签', + 'created_at' => '2019-01-04 15:35:12', + 'updated_at' => '2019-01-04 15:35:12', + 'deleted_at' => '2019-01-04 15:35:12', ], ]); } diff --git a/resources/views/admin/tag/create.blade.php b/resources/views/admin/tag/create.blade.php index 64fbfd2f..6b68abf0 100644 --- a/resources/views/admin/tag/create.blade.php +++ b/resources/views/admin/tag/create.blade.php @@ -23,6 +23,18 @@ + + {{ __('Keywords') }} + + + + + + {{ __('Description') }} + + + + diff --git a/resources/views/admin/tag/edit.blade.php b/resources/views/admin/tag/edit.blade.php index fc6b2dd7..c084bacc 100644 --- a/resources/views/admin/tag/edit.blade.php +++ b/resources/views/admin/tag/edit.blade.php @@ -23,6 +23,18 @@ + + {{ __('Keywords') }} + + + + + + {{ __('Description') }} + + + + diff --git a/resources/views/admin/tag/index.blade.php b/resources/views/admin/tag/index.blade.php index 2dc4e399..60c10609 100644 --- a/resources/views/admin/tag/index.blade.php +++ b/resources/views/admin/tag/index.blade.php @@ -35,7 +35,9 @@ @endif - {{ __('Edit') }} | + @if(is_null($v->deleted_at)) + {{ __('Edit') }} | + @endif @if(is_null($v->deleted_at)) {{ __('Delete') }} @else -- Gitee