From f1d5fc32fa2ce7c490c632f629569a12ab27f3ce Mon Sep 17 00:00:00 2001 From: George John Date: Wed, 8 Sep 2021 12:18:55 +0400 Subject: [PATCH] Updated - Migration - Seeds - Policy --- ...23_100001_create_blog_categories_table.php | 43 ----- ...21_08_23_100001_create_blog_tags_table.php | 43 ----- .../2021_08_23_100001_create_blogs_table.php | 42 +++- database/seeds/BlogTableSeeder.php | 134 +++++++++++++ database/seeds/CategoryTableSeeder.php | 133 ------------- database/seeds/TagTableSeeder.php | 181 ------------------ src/Policies/CategoryPolicy.php | 10 +- src/Policies/TagPolicy.php | 10 +- 8 files changed, 180 insertions(+), 416 deletions(-) delete mode 100644 database/migrations/2021_08_23_100001_create_blog_categories_table.php delete mode 100644 database/migrations/2021_08_23_100001_create_blog_tags_table.php delete mode 100644 database/seeds/CategoryTableSeeder.php delete mode 100644 database/seeds/TagTableSeeder.php diff --git a/database/migrations/2021_08_23_100001_create_blog_categories_table.php b/database/migrations/2021_08_23_100001_create_blog_categories_table.php deleted file mode 100644 index a313cb4..0000000 --- a/database/migrations/2021_08_23_100001_create_blog_categories_table.php +++ /dev/null @@ -1,43 +0,0 @@ -increments('id'); - $table->string('name', 255)->nullable(); - $table->string('slug', 255)->nullable(); - $table->enum('status', ['show','hide'])->nullable(); - $table->integer('user_id')->nullable(); - $table->string('user_type', 255)->nullable(); - $table->softDeletes(); - $table->nullableTimestamps(); - }); - } - - /* - * Reverse the migrations. - * - * @return void - */ - - public function down() - { - Schema::drop('blog_categories'); - } -} diff --git a/database/migrations/2021_08_23_100001_create_blog_tags_table.php b/database/migrations/2021_08_23_100001_create_blog_tags_table.php deleted file mode 100644 index dcfd71c..0000000 --- a/database/migrations/2021_08_23_100001_create_blog_tags_table.php +++ /dev/null @@ -1,43 +0,0 @@ -increments('id'); - $table->string('name', 255)->nullable(); - $table->string('slug', 255)->nullable(); - $table->enum('status', ['show','hide'])->nullable(); - $table->integer('user_id')->nullable(); - $table->string('user_type', 255)->nullable(); - $table->softDeletes(); - $table->nullableTimestamps(); - }); - } - - /* - * Reverse the migrations. - * - * @return void - */ - - public function down() - { - Schema::drop('blog_tags'); - } -} diff --git a/database/migrations/2021_08_23_100001_create_blogs_table.php b/database/migrations/2021_08_23_100001_create_blogs_table.php index 947771e..9d5a59c 100644 --- a/database/migrations/2021_08_23_100001_create_blogs_table.php +++ b/database/migrations/2021_08_23_100001_create_blogs_table.php @@ -2,7 +2,6 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\Schema; -use Illuminate\Database\Schema\Blueprint; class CreateBlogsTable extends Migration { @@ -27,23 +26,54 @@ public function up() $table->text('tags')->nullable(); $table->integer('viewcount')->nullable(); $table->string('slug', 255)->nullable(); - $table->enum('published', ['yes','no'])->nullable(); + $table->enum('published', ['yes', 'no'])->nullable(); $table->text('published_at')->nullable(); $table->integer('user_id')->nullable(); $table->string('user_type', 255)->nullable(); $table->softDeletes(); $table->nullableTimestamps(); }); + + /* + * Table: tags + */ + Schema::create('blog_tags', function ($table) { + $table->increments('id'); + $table->string('name', 255)->nullable(); + $table->string('slug', 255)->nullable(); + $table->enum('status', ['show', 'hide'])->nullable(); + $table->integer('user_id')->nullable(); + $table->string('user_type', 255)->nullable(); + $table->softDeletes(); + $table->nullableTimestamps(); + }); + + /* + * Table: categories + */ + Schema::create('blog_categories', function ($table) { + $table->increments('id'); + $table->string('name', 255)->nullable(); + $table->string('slug', 255)->nullable(); + $table->enum('status', ['show', 'hide'])->nullable(); + $table->integer('user_id')->nullable(); + $table->string('user_type', 255)->nullable(); + $table->softDeletes(); + $table->nullableTimestamps(); + }); + } /* - * Reverse the migrations. - * - * @return void - */ + * Reverse the migrations. + * + * @return void + */ public function down() { Schema::drop('blogs'); + Schema::drop('blog_tags'); + Schema::drop('blog_categories'); } } diff --git a/database/seeds/BlogTableSeeder.php b/database/seeds/BlogTableSeeder.php index 80746a6..af70c71 100644 --- a/database/seeds/BlogTableSeeder.php +++ b/database/seeds/BlogTableSeeder.php @@ -58,6 +58,140 @@ public function run() ]); + DB::table('blog_categories')->insert([ + [ + 'id' => 1, + 'name' => 'Arts and Entertainment', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 2, + 'name' => 'Branding', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 3, + 'name' => 'Design Tutorials', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 4, + 'name' => 'Designing', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 5, + 'name' => 'Feature', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + ]); + + DB::table('blog_tags')->insert([ + [ + 'id' => 1, + 'name' => 'Advertisements', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 2, + 'name' => 'Artistry', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 3, + 'name' => 'Blog', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 4, + 'name' => 'Conceptual', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 5, + 'name' => 'Design', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 6, + 'name' => 'Fashion', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 7, + 'name' => 'Inscription', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 8, + 'name' => 'Smart', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 9, + 'name' => 'Quotes', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 10, + 'name' => 'Unique', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + [ + 'id' => 11, + 'name' => 'Concepts', + 'slug' => NULL, + 'status' => 'show', + 'user_id' => 1, + 'user_type' => 'App\Models\User', + ], + ]); + DB::table('permissions')->insert([ [ 'slug' => 'blog.blog.view', diff --git a/database/seeds/CategoryTableSeeder.php b/database/seeds/CategoryTableSeeder.php deleted file mode 100644 index 6cb2ece..0000000 --- a/database/seeds/CategoryTableSeeder.php +++ /dev/null @@ -1,133 +0,0 @@ -insert([ - [ - 'id' => 1, - 'name' => 'Arts and Entertainment', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 2, - 'name' => 'Branding', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 3, - 'name' => 'Design Tutorials', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 4, - 'name' => 'Designing', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 5, - 'name' => 'Feature', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - ]); - - DB::table('permissions')->insert([ - [ - 'slug' => 'blog.category.view', - 'name' => 'View Category', - ], - [ - 'slug' => 'blog.category.create', - 'name' => 'Create Category', - ], - [ - 'slug' => 'blog.category.edit', - 'name' => 'Update Category', - ], - [ - 'slug' => 'blog.category.delete', - 'name' => 'Delete Category', - ], - - - ]); - - DB::table('menus')->insert([ - - // [ - // 'parent_id' => 1, - // 'key' => null, - // 'url' => 'admin/blog/category', - // 'name' => 'Category', - // 'description' => null, - // 'icon' => 'fa fa-newspaper-o', - // 'target' => null, - // 'order' => 190, - // 'status' => 1, - // ], - - [ - 'parent_id' => 2, - 'key' => null, - 'url' => 'user/blog/category', - 'name' => 'Category', - 'description' => null, - 'icon' => 'icon-book-open', - 'target' => null, - 'order' => 190, - 'status' => 1, - ], - - [ - 'parent_id' => 3, - 'key' => null, - 'url' => 'category', - 'name' => 'Category', - 'description' => null, - 'icon' => null, - 'target' => null, - 'order' => 190, - 'status' => 1, - ], - - ]); - - DB::table('settings')->insert([ - // Uncomment and edit this section for entering value to settings table. - /* - [ - 'pacakge' => 'Blog', - 'module' => 'Category', - 'user_type' => null, - 'user_id' => null, - 'key' => 'blog.category.key', - 'name' => 'Some name', - 'value' => 'Some value', - 'type' => 'Default', - 'control' => 'text', - ], - */ - ]); - } -} diff --git a/database/seeds/TagTableSeeder.php b/database/seeds/TagTableSeeder.php deleted file mode 100644 index b74e541..0000000 --- a/database/seeds/TagTableSeeder.php +++ /dev/null @@ -1,181 +0,0 @@ -insert([ - [ - 'id' => 1, - 'name' => 'Advertisements', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 2, - 'name' => 'Artistry', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 3, - 'name' => 'Blog', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 4, - 'name' => 'Conceptual', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 5, - 'name' => 'Design', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 6, - 'name' => 'Fashion', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 7, - 'name' => 'Inscription', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 8, - 'name' => 'Smart', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 9, - 'name' => 'Quotes', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 10, - 'name' => 'Unique', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - [ - 'id' => 11, - 'name' => 'Concepts', - 'slug' => NULL, - 'status' => 'show', - 'user_id' => 1, - 'user_type' => 'App\Models\User', - ], - ]); - - DB::table('permissions')->insert([ - [ - 'slug' => 'blog.tag.view', - 'name' => 'View Tag', - ], - [ - 'slug' => 'blog.tag.create', - 'name' => 'Create Tag', - ], - [ - 'slug' => 'blog.tag.edit', - 'name' => 'Update Tag', - ], - [ - 'slug' => 'blog.tag.delete', - 'name' => 'Delete Tag', - ], - - - ]); - - DB::table('menus')->insert([ - - // [ - // 'parent_id' => 1, - // 'key' => null, - // 'url' => 'admin/blog/tag', - // 'name' => 'Tag', - // 'description' => null, - // 'icon' => 'fa fa-newspaper-o', - // 'target' => null, - // 'order' => 190, - // 'status' => 1, - // ], - - [ - 'parent_id' => 2, - 'key' => null, - 'url' => 'user/blog/tag', - 'name' => 'Tag', - 'description' => null, - 'icon' => 'icon-book-open', - 'target' => null, - 'order' => 190, - 'status' => 1, - ], - - [ - 'parent_id' => 3, - 'key' => null, - 'url' => 'tag', - 'name' => 'Tag', - 'description' => null, - 'icon' => null, - 'target' => null, - 'order' => 190, - 'status' => 1, - ], - - ]); - - DB::table('settings')->insert([ - // Uncomment and edit this section for entering value to settings table. - /* - [ - 'pacakge' => 'Blog', - 'module' => 'Tag', - 'user_type' => null, - 'user_id' => null, - 'key' => 'blog.tag.key', - 'name' => 'Some name', - 'value' => 'Some value', - 'type' => 'Default', - 'control' => 'text', - ], - */ - ]); - } -} diff --git a/src/Policies/CategoryPolicy.php b/src/Policies/CategoryPolicy.php index d391b4c..63dc1a9 100644 --- a/src/Policies/CategoryPolicy.php +++ b/src/Policies/CategoryPolicy.php @@ -18,7 +18,7 @@ class CategoryPolicy */ public function view(UserPolicyInterface $authUser, Category $category) { - if ($authUser->canDo('blog.category.view') && $authUser->isAdmin()) { + if ($authUser->canDo('blog.blog.view') && $authUser->isAdmin()) { return true; } @@ -34,7 +34,7 @@ public function view(UserPolicyInterface $authUser, Category $category) */ public function create(UserPolicyInterface $authUser) { - return $authUser->canDo('blog.category.create'); + return $authUser->canDo('blog.blog.create'); } /** @@ -47,7 +47,7 @@ public function create(UserPolicyInterface $authUser) */ public function update(UserPolicyInterface $authUser, Category $category) { - if ($authUser->canDo('blog.category.edit') && $authUser->isAdmin()) { + if ($authUser->canDo('blog.blog.edit') && $authUser->isAdmin()) { return true; } @@ -75,7 +75,7 @@ public function destroy(UserPolicyInterface $authUser, Category $category) */ public function verify(UserPolicyInterface $authUser, Category $category) { - if ($authUser->canDo('blog.category.verify')) { + if ($authUser->canDo('blog.blog.verify')) { return true; } @@ -91,7 +91,7 @@ public function verify(UserPolicyInterface $authUser, Category $category) */ public function approve(UserPolicyInterface $authUser, Category $category) { - if ($authUser->canDo('blog.category.approve')) { + if ($authUser->canDo('blog.blog.approve')) { return true; } diff --git a/src/Policies/TagPolicy.php b/src/Policies/TagPolicy.php index 8c677bf..7c81559 100644 --- a/src/Policies/TagPolicy.php +++ b/src/Policies/TagPolicy.php @@ -18,7 +18,7 @@ class TagPolicy */ public function view(UserPolicyInterface $authUser, Tag $tag) { - if ($authUser->canDo('blog.tag.view') && $authUser->isAdmin()) { + if ($authUser->canDo('blog.blog.view') && $authUser->isAdmin()) { return true; } @@ -34,7 +34,7 @@ public function view(UserPolicyInterface $authUser, Tag $tag) */ public function create(UserPolicyInterface $authUser) { - return $authUser->canDo('blog.tag.create'); + return $authUser->canDo('blog.blog.create'); } /** @@ -47,7 +47,7 @@ public function create(UserPolicyInterface $authUser) */ public function update(UserPolicyInterface $authUser, Tag $tag) { - if ($authUser->canDo('blog.tag.edit') && $authUser->isAdmin()) { + if ($authUser->canDo('blog.blog.edit') && $authUser->isAdmin()) { return true; } @@ -75,7 +75,7 @@ public function destroy(UserPolicyInterface $authUser, Tag $tag) */ public function verify(UserPolicyInterface $authUser, Tag $tag) { - if ($authUser->canDo('blog.tag.verify')) { + if ($authUser->canDo('blog.blog.verify')) { return true; } @@ -91,7 +91,7 @@ public function verify(UserPolicyInterface $authUser, Tag $tag) */ public function approve(UserPolicyInterface $authUser, Tag $tag) { - if ($authUser->canDo('blog.tag.approve')) { + if ($authUser->canDo('blog.blog.approve')) { return true; }