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/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..ebcbb0a 100644 --- a/database/seeds/BlockTableSeeder.php +++ b/database/seeds/BlockTableSeeder.php @@ -10,85 +10,106 @@ class BlockTableSeeder extends Seeder public function run() { DB::table('blocks')->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([ + 'parent_id' => 1, + 'key' => null, + 'url' => 'admin/block/block', + 'name' => 'Blocks', + 'icon' => 'las la-dice', + '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 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/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

- -
-
-

Tags Cloud

-
- Advertisements - Artistry - Blog - Conceptual - Design - Fashion - Inscription - Smart - Quotes - Unique - Concepts -
-
\ 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..30986fe 100644 --- a/src/Block.php +++ b/src/Block.php @@ -2,32 +2,61 @@ namespace Litecms\Block; -use User; - 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; } /** - * 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) + { + + $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(); + } + + /** + * take latest blocks for public side + * @param type $count + * @param type|string $view + * @return type + */ + + public function categoryOptions($key, $value) { - return 0; + return $this->category + ->resetRepository() + ->options($key, $value); } } diff --git a/src/Forms/Block.php b/src/Forms/Block.php index c34d609..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", @@ -148,6 +153,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 +203,7 @@ public static function setAttributes() 'wrapper' => [], "label" => [], "element" => [ - 'class' => 'html-editor-mini' + 'class' => 'html-editor-mini', ], ], 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'), 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'); + } } 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');