From d967373294ef0b9cf81ae95c9170c831e6176353 Mon Sep 17 00:00:00 2001 From: George John Date: Thu, 9 Sep 2021 12:29:17 +0400 Subject: [PATCH 1/8] Update migration and seeds --- .../2021_08_07_100001_create_blocks_table.php | 13 +- database/seeds/BlockTableSeeder.php | 139 ++++++++++-------- database/seeds/CategoryTableSeeder.php | 113 -------------- 3 files changed, 85 insertions(+), 180 deletions(-) delete mode 100644 database/seeds/CategoryTableSeeder.php diff --git a/database/migrations/2021_08_07_100001_create_blocks_table.php b/database/migrations/2021_08_07_100001_create_blocks_table.php index fee403e..268907c 100644 --- a/database/migrations/2021_08_07_100001_create_blocks_table.php +++ b/database/migrations/2021_08_07_100001_create_blocks_table.php @@ -2,7 +2,6 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\Schema; -use Illuminate\Database\Schema\Blueprint; class CreateBlocksTable extends Migration { @@ -29,7 +28,7 @@ public function up() $table->text('image')->nullable(); $table->text('images')->nullable(); $table->string('slug', 200)->nullable(); - $table->enum('status', ['show','hide'])->nullable(); + $table->enum('status', ['show', 'hide'])->nullable(); $table->integer('user_id')->nullable(); $table->string('user_type', 100)->nullable(); $table->string('upload_folder', 100)->nullable(); @@ -46,7 +45,7 @@ public function up() $table->string('title', 200)->nullable(); $table->text('details')->nullable(); $table->text('image')->nullable(); - $table->enum('status', ['show','hide'])->nullable(); + $table->enum('status', ['show', 'hide'])->nullable(); $table->string('user_type', 100)->nullable(); $table->integer('user_id')->nullable(); $table->string('upload_folder', 100)->nullable(); @@ -56,10 +55,10 @@ public function up() } /* - * Reverse the migrations. - * - * @return void - */ + * Reverse the migrations. + * + * @return void + */ public function down() { diff --git a/database/seeds/BlockTableSeeder.php b/database/seeds/BlockTableSeeder.php index 4047493..5e0c6ee 100644 --- a/database/seeds/BlockTableSeeder.php +++ b/database/seeds/BlockTableSeeder.php @@ -1,7 +1,5 @@ insert([ - - ]); - - DB::table('permissions')->insert([ [ - 'slug' => 'block.block.view', - 'name' => 'View Block', + 'category_id' => '1', + 'name' => 'Powered by Laravel', + 'url' => '', + 'icon' => 'fab fa-laravel', + 'order' => '0', + 'description' => 'We have tried to make use of all features of Laravel which help you to develop the website with all resources available online.​ ', + 'image' => '', + 'slug' => 'powered-by-laravel-5-5', + 'status' => 'show', + 'user_id' => '1', + 'user_type' => 'App\\User', + 'upload_folder' => '2016/07/21/104902202', ], [ - 'slug' => 'block.block.create', - 'name' => 'Create Block', + 'category_id' => '1', + 'name' => 'Configure to your project', + 'url' => '', + 'icon' => 'fas fa-sliders-h', + 'order' => '0', + 'description' => 'Lavalite helps you to configure your Laravel projects easily. It acts as a bootstrapper for your Laravel Content Management System.', + 'image' => '', + 'slug' => 'configure-to-your-project', + 'status' => 'show', + 'user_id' => '1', + 'user_type' => 'App\\User', + 'upload_folder' => '2016/07/21/104854884', ], [ - 'slug' => 'block.block.edit', - 'name' => 'Update Block', + 'category_id' => '1', + 'name' => 'Online package builder', + 'url' => '', + 'icon' => 'fas fa-box', + 'order' => '0', + 'description' => 'The online package builder helps you to build Lavalite packages easily, The downloaded package with basic required files help you to finish your projects quickly.', + 'image' => '', + 'slug' => 'online-package-builder', + 'status' => 'show', + 'user_id' => '1', + 'user_type' => 'App\\User', + 'upload_folder' => '2016/07/21/104846403', ], + ]); + + DB::table('block_categories')->insert([ [ - 'slug' => 'block.block.delete', - 'name' => 'Delete Block', + 'id' => '1', + 'name' => 'Features', + 'slug' => 'features', + 'title' => 'Packed with features you can\'t live without.', + 'details' => 'Visit our documentation for more information.', + 'status' => 'show', + 'user_type' => 'App\\User', + 'user_id' => '1', + 'upload_folder' => '2016/10/31/163917964', + 'deleted_at' => null, + 'created_at' => '2016-07-20 07:17:48', + 'updated_at' => '2016-11-01 13:08:17', ], - - ]); - DB::table('menus')->insert([ + DB::table('menus')->insertGetId([ + 'parent_id' => 1, + 'key' => null, + 'url' => 'admin/block/block', + 'name' => 'Blocks', + 'icon' => 'las fa-th-large', + 'target' => null, + 'order' => 100, + 'status' => 1, + ]); + DB::table('permissions')->insert([ [ - 'parent_id' => 1, - 'key' => null, - 'url' => 'admin/block/block', - 'name' => 'Block', - 'description' => null, - 'icon' => 'fa fa-newspaper-o', - 'target' => null, - 'order' => 190, - 'status' => 1, + 'slug' => 'block.block.view', + 'name' => 'View Block', ], - [ - 'parent_id' => 2, - 'key' => null, - 'url' => 'user/block/block', - 'name' => 'Block', - 'description' => null, - 'icon' => 'icon-book-open', - 'target' => null, - 'order' => 190, - 'status' => 1, + 'slug' => 'block.block.create', + 'name' => 'Create Block', ], - [ - 'parent_id' => 3, - 'key' => null, - 'url' => 'block', - 'name' => 'Block', - 'description' => null, - 'icon' => null, - 'target' => null, - 'order' => 190, - 'status' => 1, + 'slug' => 'block.block.edit', + 'name' => 'Update Block', + ], + [ + 'slug' => 'block.block.delete', + 'name' => 'Delete Block', ], - ]); DB::table('settings')->insert([ // Uncomment and edit this section for entering value to settings table. /* - [ - 'pacakge' => 'Block', - 'module' => 'Block', - 'user_type' => null, - 'user_id' => null, - 'key' => 'block.block.key', - 'name' => 'Some name', - 'value' => 'Some value', - 'type' => 'Default', - 'control' => 'text', - ], - */ - ]); + [ + 'key' => 'block.block.key', + 'name' => 'Some name', + 'value' => 'Some value', + 'type' => 'Default', + ], + */]); } } diff --git a/database/seeds/CategoryTableSeeder.php b/database/seeds/CategoryTableSeeder.php deleted file mode 100644 index 783674f..0000000 --- a/database/seeds/CategoryTableSeeder.php +++ /dev/null @@ -1,113 +0,0 @@ -insert([ - [ - 'category_id' => '1', - 'name' => 'Powered by Laravel', - 'url' => '', - 'icon' => 'fab fa-laravel', - 'order' => '0', - 'description' => 'We have tried to make use of all features of Laravel which help you to develop the website with all resources available online.​ ', - 'image' => '', - 'slug' => 'powered-by-laravel-5-5', - 'status' => 'show', - 'user_id' => '1', - 'user_type' => 'App\\User', - 'upload_folder' => '2016/07/21/104902202', - ], - [ - 'category_id' => '1', - 'name' => 'Configure to your project', - 'url' => '', - 'icon' => 'fas fa-sliders-h', - 'order' => '0', - 'description' => 'Lavalite helps you to configure your Laravel projects easily. It acts as a bootstrapper for your Laravel Content Management System.', - 'image' => '', - 'slug' => 'configure-to-your-project', - 'status' => 'show', - 'user_id' => '1', - 'user_type' => 'App\\User', - 'upload_folder' => '2016/07/21/104854884', - ], - [ - 'category_id' => '1', - 'name' => 'Online package builder', - 'url' => '', - 'icon' => 'fas fa-box', - 'order' => '0', - 'description' => 'The online package builder helps you to build Lavalite packages easily, The downloaded package with basic required files help you to finish your projects quickly.', - 'image' => '', - 'slug' => 'online-package-builder', - 'status' => 'show', - 'user_id' => '1', - 'user_type' => 'App\\User', - 'upload_folder' => '2016/07/21/104846403', - ], - ]); - - DB::table('block_categories')->insert([ - [ - 'id' => '1', - 'name' => 'Features', - 'slug' => 'features', - 'title' => 'Packed with features you can\'t live without.', - 'details' => 'Visit our documentation for more information.', - 'status' => 'show', - 'user_type' => 'App\\User', - 'user_id' => '1', - 'upload_folder' => '2016/10/31/163917964', - 'deleted_at' => null, - 'created_at' => '2016-07-20 07:17:48', - 'updated_at' => '2016-11-01 13:08:17', - ], - ]); - - $id = DB::table('menus')->insertGetId([ - 'parent_id' => 1, - 'key' => null, - 'url' => 'admin/block/block', - 'name' => 'Blocks', - 'icon' => 'las fa-th-large', - 'target' => null, - 'order' => 100, - 'status' => 1, - ]); - - DB::table('permissions')->insert([ - [ - 'slug' => 'block.block.view', - 'name' => 'View Block', - ], - [ - 'slug' => 'block.block.create', - 'name' => 'Create Block', - ], - [ - 'slug' => 'block.block.edit', - 'name' => 'Update Block', - ], - [ - 'slug' => 'block.block.delete', - 'name' => 'Delete Block', - ] - ]); - - DB::table('settings')->insert([ - // Uncomment and edit this section for entering value to settings table. - /* - [ - 'key' => 'block.block.key', - 'name' => 'Some name', - 'value' => 'Some value', - 'type' => 'Default', - ], - */]); - } -} \ No newline at end of file From 02478d2cbf30dde5cc61d93c1d5220f9345370a6 Mon Sep 17 00:00:00 2001 From: George John Date: Thu, 9 Sep 2021 12:43:21 +0400 Subject: [PATCH 2/8] Update icon on seed --- database/seeds/BlockTableSeeder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/seeds/BlockTableSeeder.php b/database/seeds/BlockTableSeeder.php index 5e0c6ee..0b68f98 100644 --- a/database/seeds/BlockTableSeeder.php +++ b/database/seeds/BlockTableSeeder.php @@ -69,12 +69,12 @@ public function run() ], ]); - DB::table('menus')->insertGetId([ + DB::table('menus')->insert([ 'parent_id' => 1, 'key' => null, 'url' => 'admin/block/block', 'name' => 'Blocks', - 'icon' => 'las fa-th-large', + 'icon' => 'las la-boxes', 'target' => null, 'order' => 100, 'status' => 1, From 9363b1d1e3d48be95e4e920dff8b04eb7939335d Mon Sep 17 00:00:00 2001 From: George John Date: Thu, 9 Sep 2021 13:12:56 +0400 Subject: [PATCH 3/8] Updated icons --- database/seeds/BlockTableSeeder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/seeds/BlockTableSeeder.php b/database/seeds/BlockTableSeeder.php index 0b68f98..498ae5f 100644 --- a/database/seeds/BlockTableSeeder.php +++ b/database/seeds/BlockTableSeeder.php @@ -74,7 +74,7 @@ public function run() 'key' => null, 'url' => 'admin/block/block', 'name' => 'Blocks', - 'icon' => 'las la-boxes', + 'icon' => 'las la-dice', 'target' => null, 'order' => 100, 'status' => 1, From 0666dbdae325ebc20a487d03306cebc945877c1d Mon Sep 17 00:00:00 2001 From: George John Date: Thu, 9 Sep 2021 16:00:17 +0400 Subject: [PATCH 4/8] Block seeds --- database/seeds/BlockTableSeeder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/database/seeds/BlockTableSeeder.php b/database/seeds/BlockTableSeeder.php index 498ae5f..ebcbb0a 100644 --- a/database/seeds/BlockTableSeeder.php +++ b/database/seeds/BlockTableSeeder.php @@ -1,5 +1,7 @@ Date: Thu, 23 Sep 2021 14:34:24 +0400 Subject: [PATCH 5/8] Update block display --- resources/views/public/block/aside.blade.php | 57 ------------- resources/views/public/block/header.blade.php | 12 --- resources/views/public/block/index.blade.php | 79 ------------------- resources/views/public/block/show.blade.php | 28 ------- resources/views/public/default.blade.php | 13 +++ src/Block.php | 25 +++--- src/Models/Block.php | 13 +++ src/Models/Category.php | 8 +- 8 files changed, 49 insertions(+), 186 deletions(-) delete mode 100644 resources/views/public/block/aside.blade.php delete mode 100644 resources/views/public/block/header.blade.php delete mode 100644 resources/views/public/block/index.blade.php delete mode 100644 resources/views/public/block/show.blade.php create mode 100644 resources/views/public/default.blade.php diff --git a/resources/views/public/block/aside.blade.php b/resources/views/public/block/aside.blade.php deleted file mode 100644 index d596363..0000000 --- a/resources/views/public/block/aside.blade.php +++ /dev/null @@ -1,57 +0,0 @@ -
-
-
- - -
-
-
-
-

Categories

- -
-
-

Recently Added

- -
- \ No newline at end of file diff --git a/resources/views/public/block/header.blade.php b/resources/views/public/block/header.blade.php deleted file mode 100644 index 636cbc1..0000000 --- a/resources/views/public/block/header.blade.php +++ /dev/null @@ -1,12 +0,0 @@ -
-
-
-
- -
-
-
-
\ No newline at end of file diff --git a/resources/views/public/block/index.blade.php b/resources/views/public/block/index.blade.php deleted file mode 100644 index 50300b9..0000000 --- a/resources/views/public/block/index.blade.php +++ /dev/null @@ -1,79 +0,0 @@ -@include('block::public.block.header') - -
-
-
-
- @include('block::public.block.aside') -
- -
-
-
\ No newline at end of file diff --git a/resources/views/public/block/show.blade.php b/resources/views/public/block/show.blade.php deleted file mode 100644 index 50596cb..0000000 --- a/resources/views/public/block/show.blade.php +++ /dev/null @@ -1,28 +0,0 @@ - @include('block::public.block.header') -
-
-
-
- @include('block::public.block.aside') -
- -
-
-
\ No newline at end of file diff --git a/resources/views/public/default.blade.php b/resources/views/public/default.blade.php new file mode 100644 index 0000000..b894c1a --- /dev/null +++ b/resources/views/public/default.blade.php @@ -0,0 +1,13 @@ +@foreach ($blocks as $block) +
+
+
+ +
+
+

{!!$block->name!!}

+

{!!$block->description!!}

+
+
+
+@endforeach diff --git a/src/Block.php b/src/Block.php index 2af7edd..369b058 100644 --- a/src/Block.php +++ b/src/Block.php @@ -2,8 +2,6 @@ namespace Litecms\Block; -use User; - class Block { /** @@ -20,14 +18,23 @@ public function __construct(\Litecms\Block\Interfaces\CategoryRepositoryInterfac } /** - * Returns count of block. - * - * @param array $filter - * - * @return int + * take latest blocks for public side + * @param type $count + * @param type|string $view + * @return type */ - public function count() + + public function display($category) { - return 0; + + $view = (view()->exists("block::public.{$category}")) ? "block::public.{$category}" : "block::public.default"; + + $category = $this->category + ->scopeQuery(function ($query) use ($category) { + return $query->with('blocks')->whereSlug($category); + })->first(); + + $blocks = $category->blocks; + return view($view, compact('blocks', 'category'))->render(); } } diff --git a/src/Models/Block.php b/src/Models/Block.php index 24ba907..1523156 100644 --- a/src/Models/Block.php +++ b/src/Models/Block.php @@ -26,5 +26,18 @@ class Block extends Model */ protected $config = 'litecms.block.block.model'; + /** + * The blog_categories that belong to the blog. + */ + public function category() + { + + return $this->belongsTo('Litecms\Block\Models\Category', 'category_id'); + } + + public function user() + { + return $this->belongsTo('App\User', 'user_id'); + } } diff --git a/src/Models/Category.php b/src/Models/Category.php index d2ba149..dce8756 100644 --- a/src/Models/Category.php +++ b/src/Models/Category.php @@ -26,5 +26,11 @@ class Category extends Model */ protected $config = 'litecms.block.category.model'; - + /** + * The categories that belong to the blog. + */ + public function blocks() + { + return $this->hasMany('Litecms\Block\Models\Block', 'category_id'); + } } From e2e7db729f034ec274751b8a9855fd4ef812244f Mon Sep 17 00:00:00 2001 From: George John Date: Thu, 23 Sep 2021 18:48:29 +0400 Subject: [PATCH 6/8] Updated category for block --- src/Block.php | 28 +++++++++++++++++++++++++--- src/Forms/Block.php | 5 ++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Block.php b/src/Block.php index 369b058..30986fe 100644 --- a/src/Block.php +++ b/src/Block.php @@ -5,16 +5,24 @@ class Block { /** - * $category object. + * Category repository object. */ protected $category; + /** + * Block repository object. + */ + protected $block; + /** * Constructor. */ - public function __construct(\Litecms\Block\Interfaces\CategoryRepositoryInterface $category) - { + public function __construct( + \Litecms\Block\Interfaces\CategoryRepositoryInterface $category, + \Litecms\Block\Interfaces\BlockRepositoryInterface $block + ) { $this->category = $category; + $this->block = $block; } /** @@ -37,4 +45,18 @@ public function display($category) $blocks = $category->blocks; return view($view, compact('blocks', 'category'))->render(); } + + /** + * take latest blocks for public side + * @param type $count + * @param type|string $view + * @return type + */ + + public function categoryOptions($key, $value) + { + return $this->category + ->resetRepository() + ->options($key, $value); + } } diff --git a/src/Forms/Block.php b/src/Forms/Block.php index c34d609..0f2e4e6 100644 --- a/src/Forms/Block.php +++ b/src/Forms/Block.php @@ -148,6 +148,9 @@ public static function setAttributes() "placeholder" => trans('block::block.placeholder.category_id'), "rules" => '', "group" => "main", + 'options' => function () { + return \Block::categoryOptions('id', 'name'); + }, "section" => "first", "col" => "4", "append" => null, @@ -195,7 +198,7 @@ public static function setAttributes() 'wrapper' => [], "label" => [], "element" => [ - 'class' => 'html-editor-mini' + 'class' => 'html-editor-mini', ], ], From 015e410f4f34561039b4b1318d5c98dd1783ffdb Mon Sep 17 00:00:00 2001 From: George John Date: Mon, 4 Oct 2021 17:15:46 +0400 Subject: [PATCH 7/8] Update for the theme. --- src/Forms/Block.php | 5 +++++ src/Forms/Category.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/Forms/Block.php b/src/Forms/Block.php index 0f2e4e6..de22436 100644 --- a/src/Forms/Block.php +++ b/src/Forms/Block.php @@ -57,6 +57,11 @@ public static function setAttributes() 'details' => trans('block::block.groups.details'), 'images' => trans('block::block.groups.images'), ]; + self::$orderBy = [ + 'created_at' => trans('blog::blog.label.created_at'), + 'name' => trans('blog::blog.label.title'), + 'status' => trans('blog::blog.label.status'), + ]; self::$list = [ [ 'key' => "ref", diff --git a/src/Forms/Category.php b/src/Forms/Category.php index 9ab783c..6f9bba1 100644 --- a/src/Forms/Category.php +++ b/src/Forms/Category.php @@ -52,6 +52,11 @@ public static function setAttributes() "roles" => [], ] ]; + self::$orderBy = [ + 'created_at' => trans('blog::blog.label.created_at'), + 'name' => trans('blog::blog.label.title'), + 'status' => trans('blog::blog.label.status'), + ]; self::$groups = [ 'main' => trans('block::block.groups.main'), 'details' => trans('block::block.groups.details'), From 9383c83adc4ae1077111bebd8c19af17f3d42b1f Mon Sep 17 00:00:00 2001 From: George John Date: Sun, 6 Mar 2022 11:51:01 +0400 Subject: [PATCH 8/8] Update for Lavalite 9.x --- composer.json | 2 +- {resources/lang => lang}/en/block.php | 0 {resources/lang => lang}/en/category.php | 0 {resources/lang => lang}/en/package.php | 0 src/Providers/BlockServiceProvider.php | 2 +- 5 files changed, 2 insertions(+), 2 deletions(-) rename {resources/lang => lang}/en/block.php (100%) rename {resources/lang => lang}/en/category.php (100%) rename {resources/lang => lang}/en/package.php (100%) diff --git a/composer.json b/composer.json index 633063f..077dad3 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": "^7.3|^8.0", + "php": "^8.0.2", "composer/installers": "~2.0" }, "autoload": { diff --git a/resources/lang/en/block.php b/lang/en/block.php similarity index 100% rename from resources/lang/en/block.php rename to lang/en/block.php diff --git a/resources/lang/en/category.php b/lang/en/category.php similarity index 100% rename from resources/lang/en/category.php rename to lang/en/category.php diff --git a/resources/lang/en/package.php b/lang/en/package.php similarity index 100% rename from resources/lang/en/package.php rename to lang/en/package.php diff --git a/src/Providers/BlockServiceProvider.php b/src/Providers/BlockServiceProvider.php index 206019c..3f73d1f 100644 --- a/src/Providers/BlockServiceProvider.php +++ b/src/Providers/BlockServiceProvider.php @@ -25,7 +25,7 @@ public function boot() $this->loadViewsFrom(__DIR__ . '/../../resources/views', 'block'); // Load translation - $this->loadTranslationsFrom(__DIR__ . '/../../resources/lang', 'block'); + $this->loadTranslationsFrom(__DIR__ . '/../../lang', 'block'); // Load migrations $this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');