diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 9a3b51a..b101baf 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -1419,8 +1419,24 @@ function findArea($name,$model = null) return \App\Models\Area::where('name', $name)->first(); } - +/** + * cache number + * @return false|mixed|string|null + */ function cacheNumber() { return getSetting('cache_number'); } + + +/** + * get website main categories + * @param $limit + * @param $orderBy + * @param $asc + * @return Category[]|\LaravelIdea\Helper\App\Models\_IH_Category_C + */ +function getMainCategory($limit=4,$orderBy = 'id', $asc = 'ASC') +{ + return \App\Models\Category::whereNull('parent_id')->limit($limit)->orderBy($orderBy,$asc)->get(); +} diff --git a/app/Http/Controllers/Admin/CategoryController.php b/app/Http/Controllers/Admin/CategoryController.php index fbd1068..1229ac6 100644 --- a/app/Http/Controllers/Admin/CategoryController.php +++ b/app/Http/Controllers/Admin/CategoryController.php @@ -56,6 +56,7 @@ class CategoryController extends XController $category->name = $request->input('name'); $category->subtitle = $request->input('subtitle'); + $category->icon = $request->input('icon'); $category->description = $request->input('description'); if ($category->parent_id != ''){ $category->parent_id = $request->input('parent_id',null); @@ -83,6 +84,7 @@ class CategoryController extends XController config('app.media.watermark_opacity')); } $i->save(storage_path() . '/app/public/categories/optimized-'. $category->$key); + } if ($request->has('bg')) { $category->bg = $this->storeFile('bg', $category, 'categories'); @@ -104,6 +106,10 @@ class CategoryController extends XController } $i->save(storage_path() . '/app/public/categories/optimized-'. $category->$key); } + + if ($request->has('svg')){ + $category->svg = $this->storeFile('svg',$category, 'categories'); + } $category->save(); return $category; diff --git a/app/Models/Category.php b/app/Models/Category.php index 1643d47..c77dc82 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -22,6 +22,14 @@ class Category extends Model return \Storage::url('categories/optimized-' . $this->image); } + public function svgUrl() + { + if ($this->svg == null) { + return asset('/assets/upload/logo.svg'); + } + + return \Storage::url('categories/' . $this->svg); + } public function imgOriginalUrl() { diff --git a/database/migrations/2024_05_07_125838_create_categories_table.php b/database/migrations/2024_05_07_125838_create_categories_table.php index e15295c..992d28e 100644 --- a/database/migrations/2024_05_07_125838_create_categories_table.php +++ b/database/migrations/2024_05_07_125838_create_categories_table.php @@ -16,9 +16,11 @@ return new class extends Migration $table->text('name'); $table->string('slug',128)->unique(); $table->text('subtitle')->nullable(); + $table->string('icon')->nullable(); $table->text('description')->nullable(); $table->integer('sort')->default(0); $table->string('image',2048)->nullable()->default(null); + $table->string('svg',2048)->nullable()->default(null); $table->string('bg',2048)->nullable()->default(null); $table->unsignedInteger('parent_id')->nullable()->default(null)->index(); $table->json('theme')->nullable(); diff --git a/resources/views/admin/categories/category-form.blade.php b/resources/views/admin/categories/category-form.blade.php index d5844e2..cee7d33 100644 --- a/resources/views/admin/categories/category-form.blade.php +++ b/resources/views/admin/categories/category-form.blade.php @@ -24,6 +24,16 @@ +
+

+ + {{__("Icon")}} +

+
+ +
+
+ @if(isset($item))

@@ -43,6 +53,17 @@

@endif + @if(isset($item)) +
+

+ + {{__('SVG image')}} +

+ {{$item->name}} + +
+ @endif + @if(isset($item))
@@ -107,7 +128,7 @@ value="{{old('subtitle',$item->subtitle??null)}}"/>
-
+
@@ -124,7 +145,7 @@ @endforeach
-
+
-
+
+
+ + +
+
+