diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 13fa41a..884d7d2 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -1,6 +1,7 @@ toArray(); $attrs = $model->getMutatedAttributes(); - $attrs = array_diff($attrs,['translations']); + $attrs = array_diff($attrs, ['translations']); foreach ($attrs as $attr) { $data[$attr] = $model->getAttribute($attr); } @@ -445,7 +447,8 @@ function modelWithCustomAttrs($model){ * get max size for upload * @return int */ -function getMaxUploadSize() { +function getMaxUploadSize() +{ $uploadMaxSize = returnBytes(ini_get('upload_max_filesize')); $postMaxSize = returnBytes(ini_get('post_max_size')); @@ -458,10 +461,11 @@ function getMaxUploadSize() { * @param $val * @return float|int|string */ -function returnBytes($val) { - $last = strtolower($val[strlen($val)-1]); - $val = trim(strtolower($val),'kgm'); - switch($last) { +function returnBytes($val) +{ + $last = strtolower($val[strlen($val) - 1]); + $val = trim(strtolower($val), 'kgm'); + switch ($last) { // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024 * 1024 * 1024; @@ -480,7 +484,8 @@ function returnBytes($val) { * @param $size * @return string */ -function formatFileSize($size) { +function formatFileSize($size) +{ if ($size < 1024) { return $size . ' bytes'; } elseif ($size < 1048576) { @@ -498,7 +503,8 @@ function formatFileSize($size) { * @param $length * @return string */ -function generateUniqueID($length = 8) { +function generateUniqueID($length = 8) +{ $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; $uniqueID = ''; @@ -510,17 +516,91 @@ function generateUniqueID($length = 8) { return $uniqueID; } - +/** + * comment status to bypass blade error + * @return array[] + */ function commentStatuses() { return [ - ['name' => __("Approved"), 'id' => '1' ], - ['name' => __("Rejected"), 'id' => '-1' ], - ['name' => __("Pending"), 'id' => '0' ] + ['name' => __("Approved"), 'id' => '1'], + ['name' => __("Rejected"), 'id' => '-1'], + ['name' => __("Pending"), 'id' => '0'] ]; } -function getSetting(){ - return 'test@xshop.ir'; + + +/** + * validate basic setting request b4 save + * @param $setting + * @param $newValue + * @return mixed|string + */ +function validateSettingRequest($setting, $newValue) +{ + if (!$setting->is_basic) { + return $newValue; + } + + switch ($setting->key) { + case 'optimize': + if ($newValue != 'jpg' || $newValue != 'webp') { + return 'webp'; + } + case 'gallery_thumb': + case 'post_thumb': + case 'product_thumb': + case 'product_image': + $temp = explode('x', $newValue); + if (count($temp) != 2) { + return '500x500'; + } else { + if ((int)$temp[0] < 50 || (int)$temp[1] < 50) { + return '500x500'; + } + } + } + return $newValue; +} + + +/*** + * get setting by key + * @param string $key setting key + * @return false|mixed|string|null + */ +function getSetting($key) +{ + if (!isset($_SERVER['SERVER_NAME']) || !\Schema::hasTable('settings')) { + return false; + } + $x = Setting::where('key', $key)->first(); + if ($x == null) { +// $a = new \stdClass(); + return ''; + } + if (config('app.xlang') && ($x->type == 'group' || $x->type == 'category')) { + $defLang = config('app.xlang_main'); + return $x->getTranslations('value')[$defLang]; + } + return $x->value; +} + +function imageSizeConvertValidate($size){ + $s = getSetting($size); + if ($s == null){ + + $t = explode('x',$size); + if (config('app.media'.$size) == null || config('app.media'.$size) == ''){ + $t[0] = 500 ; + $t[1] = 500 ; + } + + }else{ + $t = explode('x',$s); + } + return $t; + } diff --git a/app/Http/Controllers/Admin/SettingController.php b/app/Http/Controllers/Admin/SettingController.php new file mode 100644 index 0000000..45349fd --- /dev/null +++ b/app/Http/Controllers/Admin/SettingController.php @@ -0,0 +1,102 @@ +orderBy('section')->get(); //ESH// just active setting`s show + $cats = Category::all(['id','name']); + $groups = Group::all(['id','name']); + return view('admin.commons.setting', + compact('settings', 'cats','groups')); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + // + } + + /** + * Store a newly created resource in storage. + */ + public function store(SettingSaveRequest $request) + { + // + $set = new Setting(); + $set->title = $request->title; + $set->key = $request->key; + $set->section = $request->section; + $set->type = $request->type; + $set->size = $request->size; + $set->save(); + return redirect()->back()->with(['message' => __('Setting added to website')]); + } + + /** + * Display the specified resource. + */ + public function show(Setting $setting) + { + // + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(Setting $setting) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request) + { + $all = $request->all(); + foreach ($all as $key => $val) { + $set = Setting::where('key', $key)->first(); + if ($set != null && !$request->hasFile($key)) { + + $set->value = validateSettingRequest($set,$val); + $set->save(); + } + } + $files = $request->allFiles(); + if (isset($files['file'])) { + foreach ($files['file'] as $index => $file) { + if ($file->extension() == 'mp4' || $file->extension() == 'mp3'){ + $file->move(public_path('upload/media/'), str_replace('_','.',$index) );//store('/images/'.,['disk' => 'public']); + }else{ + $file->move(public_path('upload/images/'), str_replace('_','.',$index) );//store('/images/'.,['disk' => 'public']); + } + } + } + return redirect()->back()->with(['message' => __('Setting of website updated')]); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(Setting $setting) + { + // + } +} diff --git a/app/Http/Requests/SettingSaveRequest.php b/app/Http/Requests/SettingSaveRequest.php new file mode 100644 index 0000000..de2ef8a --- /dev/null +++ b/app/Http/Requests/SettingSaveRequest.php @@ -0,0 +1,32 @@ +check() && auth()->user()->hasRole('developer'); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array|string> + */ + public function rules(): array + { + return [ + 'title' => ['required', 'string','min:3', 'max:255'], + 'key' => ['required', 'string', 'alpha_dash', 'max:255', "unique:settings,key,".$this->id], + 'type' => ['required', 'string'], + 'section' => ['required', 'string', 'max:255', 'min:2'], + 'size' => ['required','integer','min:1','max:12'] + ]; + } +} diff --git a/app/Models/Gallery.php b/app/Models/Gallery.php index 8082e99..bfb23d3 100644 --- a/app/Models/Gallery.php +++ b/app/Models/Gallery.php @@ -4,6 +4,9 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Spatie\Image\Enums\AlignPosition; +use Spatie\Image\Enums\Fit; +use Spatie\Image\Enums\Unit; use Spatie\MediaLibrary\Conversions\Manipulations; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; @@ -25,20 +28,21 @@ class Gallery extends Model implements HasMedia { $this->addMediaConversion('gallery-image')->optimize(); - $t = explode('x',config('app.media.gallery_thumb')); + $t = imageSizeConvertValidate('gallery_thumb'); - if (config('starter-kit.gallery_thumb') == null || config('starter-kit.gallery_thumb') == ''){ - $t[0] = 500 ; - $t[1] = 500 ; - } - - - $this->addMediaConversion('gthumb')->width($t[0]) + $mc = $this->addMediaConversion('gthumb')->width($t[0]) ->height($t[1]) ->nonQueued() - ->crop( $t[0], $t[1])->optimize(); -// ->watermark(public_path('images/logo.png'))->watermarkOpacity(50); -// ->withResponsiveImages(); + ->crop( $t[0], $t[1]) + ->optimize() + ->format(getSetting('optimize')); + if (getSetting('watermark')){ + $mc->watermark(public_path('upload/images/logo.png'), + AlignPosition::BottomLeft,5,5,Unit::Percent, + 15,Unit::Percent,15,Unit::Percent,Fit::Contain,50); + } + +// ->withResponsiveImages(); } public function getRouteKeyName() diff --git a/app/Models/Image.php b/app/Models/Image.php index 26e76a1..9ea14be 100644 --- a/app/Models/Image.php +++ b/app/Models/Image.php @@ -4,6 +4,9 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Spatie\Image\Enums\AlignPosition; +use Spatie\Image\Enums\Fit; +use Spatie\Image\Enums\Unit; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; @@ -24,18 +27,23 @@ class Image extends Model implements HasMedia public function registerMediaConversions(Media $media = null): void { - $t = explode('x', config('starter-kit.post_thumb')); - if (config('starter-kit.gallery_thumb') == null || config('starter-kit.gallery_thumb') == '') { - $t[0] = 500; - $t[1] = 500; - } + $t = imageSizeConvertValidate('gallery_thumb'); $this->addMediaConversion('image-image')->optimize(); - $this->addMediaConversion('gthumb')->width($t[0]) + $mc = $this->addMediaConversion('githumb') + ->width($t[0]) ->height($t[1]) ->nonQueued() - ->crop( $t[0], $t[1])->optimize(); + ->crop( $t[0], $t[1]) + ->optimize() + ->format(getSetting('optimize')); + + if (getSetting('watermark')){ + $mc->watermark(public_path('upload/images/logo.png'), + AlignPosition::BottomLeft,5,5,Unit::Percent, + 15,Unit::Percent,15,Unit::Percent,Fit::Contain,50); + } // ->watermark(public_path('images/logo.png'))->watermarkOpacity(50); // ->withResponsiveImages(); } @@ -43,9 +51,9 @@ class Image extends Model implements HasMedia public function imgurl() { if ($this->getMedia()->count() > 0) { - return $this->getMedia()->first()->getUrl('gthumb'); + return $this->getMedia()->first()->getUrl('githumb'); } else { - return "no image"; + return asset('assets/upload/logo.svg'); } } } diff --git a/app/Models/Post.php b/app/Models/Post.php index 05d7997..a96bdf5 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -5,6 +5,9 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Spatie\Image\Enums\AlignPosition; +use Spatie\Image\Enums\Fit; +use Spatie\Image\Enums\Unit; use Spatie\MediaLibrary\MediaCollections\Models\Media; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; @@ -38,19 +41,22 @@ class Post extends Model implements HasMedia { $t = explode('x', config('app.media.post_thumb')); - if (config('app.media.post_thumb') == null || config('app.media.post_thumb') == '') { - $t[0] = 500; - $t[1] = 500; - } + $t = imageSizeConvertValidate('post_thumb'); - $this->addMediaConversion('post-image') + $mc = $this->addMediaConversion('post-image') ->width($t[0]) ->height($t[1]) ->crop( $t[0], $t[1]) ->optimize() ->sharpen(10) ->nonQueued() - ->format('webp'); + ->format(getSetting('optimize')); + + if (getSetting('watermark')){ + $mc->watermark(public_path('upload/images/logo.png'), + AlignPosition::BottomLeft,5,5,Unit::Percent, + 15,Unit::Percent,15,Unit::Percent,Fit::Contain,50); + } } diff --git a/app/Models/Product.php b/app/Models/Product.php index c7803b9..829467e 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -6,6 +6,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Plank\Metable\Metable; +use Spatie\Image\Enums\AlignPosition; +use Spatie\Image\Enums\Fit; +use Spatie\Image\Enums\Unit; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; @@ -49,37 +52,36 @@ class Product extends Model implements HasMedia public function registerMediaConversions(?Media $media = null): void { - $ti = explode('x', config('app.media.product_image')); + $ti = imageSizeConvertValidate('product_image'); + $t = imageSizeConvertValidate('product_thumb'); - if (config('app.media.product_image') == null || config('app.media.product_image') == '') { - $ti[0] = 1200; - $ti[1] = 1200; - } - $t = explode('x', config('app.media.product_thumb')); - - if (config('app.media.product_thumb') == null || config('app.media.product_thumb') == '') { - $t[0] = 500; - $t[1] = 500; - } - - $this->addMediaConversion('product-thumb') + $mc = $this->addMediaConversion('product-thumb') ->width($t[0]) ->height($t[1]) ->crop($t[0], $t[1]) ->optimize() ->sharpen(10) ->nonQueued() - ->format('webp'); + ->format(getSetting('optimize')); - $this->addMediaConversion('product-image') + $mc2 = $this->addMediaConversion('product-image') ->width($ti[0]) ->height($ti[1]) ->crop($ti[0], $ti[1]) ->optimize() ->sharpen(10) ->nonQueued() - ->format('webp'); + ->format(getSetting('optimize')); + + if (getSetting('watermark')){ + $mc->watermark(public_path('upload/images/logo.png'), + AlignPosition::BottomLeft,5,5,Unit::Percent, + 15,Unit::Percent,15,Unit::Percent,Fit::Contain,50); + $mc2->watermark(public_path('upload/images/logo.png'), + AlignPosition::BottomLeft,5,5,Unit::Percent, + 15,Unit::Percent,15,Unit::Percent,Fit::Contain,50); + } } @@ -146,6 +148,13 @@ class Product extends Model implements HasMedia } public function imgUrl(){ + if ($this->getMedia()->count() > 0) { + return $this->getMedia()[$this->image_index]->getUrl('product-image'); + } else { + return asset('assets/upload/logo.svg'); + } + } + public function orginalImageUrl(){ if ($this->getMedia()->count() > 0) { return $this->getMedia()[$this->image_index]->getUrl(); } else { @@ -154,7 +163,7 @@ class Product extends Model implements HasMedia } public function imgUrl2(){ if ($this->getMedia()->count() > 0 && isset($this->getMedia()[1])) { - return $this->getMedia()[1]->getUrl(); + return $this->getMedia()[1]->getUrl('product-image'); } else { return asset('assets/upload/logo.svg'); } diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 0fe60af..5487721 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -4,8 +4,14 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Spatie\Translatable\HasTranslations; class Setting extends Model { - use HasFactory; + use HasFactory, HasTranslations; + + public $translatable = ['value']; + + public static $settingTypes = ['TEXT', 'LONGTEXT', 'CODE', 'EDITOR', + 'CATEGORY', 'GROUP', 'CHECKBOX', 'FILE']; } diff --git a/database/migrations/2024_05_07_133136_create_settings_table.php b/database/migrations/2024_05_07_133136_create_settings_table.php index e61c7b0..8806201 100644 --- a/database/migrations/2024_05_07_133136_create_settings_table.php +++ b/database/migrations/2024_05_07_133136_create_settings_table.php @@ -14,11 +14,14 @@ return new class extends Migration Schema::create('settings', function (Blueprint $table) { $table->id(); $table->string('section'); - $table->string('type'); + $table->enum('type',\App\Models\Setting::$settingTypes); $table->string('title'); $table->boolean('active')->default(true); $table->string('key')->unique(); $table->text('value')->nullable(); + $table->boolean('ltr')->default(false); + $table->boolean('is_basic')->default(false); + $table->boolean('size')->default('12'); $table->timestamps(); }); } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index c4a4826..400b0b0 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -32,6 +32,7 @@ class DatabaseSeeder extends Seeder PropSeeder::class, ProductSeeder::class, CommentSeeder::class, + SettingSeeder::class, ] ); } diff --git a/database/seeders/SettingSeeder.php b/database/seeders/SettingSeeder.php index 9a6d9b6..666cf2f 100644 --- a/database/seeders/SettingSeeder.php +++ b/database/seeders/SettingSeeder.php @@ -2,6 +2,7 @@ namespace Database\Seeders; +use App\Models\Setting; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; @@ -13,5 +14,174 @@ class SettingSeeder extends Seeder public function run(): void { // + $sections = [ + 'General' => [ + [ + 'title' => __("Email"), + 'key' => 'email', + 'type' => 'TEXT', + 'ltr' => true, + 'value' => 'xshop@xstack.ir', + 'size' => '6', + ], + [ + 'title' => __("Tel"), + 'key' => 'tel', + 'type' => 'TEXT', + 'ltr' => true, + 'value' => '+98-21-9988-7766', + 'size' => '6', + ], + [ + 'title' => __("Subtitle"), + 'key' => 'subtitle', + 'type' => 'TEXT', + 'value' => 'another shop with xShop', + ], + [ + 'title' => __("copyright"), + 'key' => 'copyright', + 'type' => 'TEXT', + 'value' => 'xShop community © ' . date('Y'), + ], + [ + 'title' => __("Twitter (x)"), + 'key' => 'tw', + 'type' => 'TEXT', + 'size' => '4', + ], + [ + 'title' => __("Facebook"), + 'key' => 'fb', + 'type' => 'TEXT', + 'size' => '4', + ], + [ + 'title' => __("Instagram"), + 'key' => 'in', + 'type' => 'TEXT', + 'size' => '4', + ], + [ + 'title' => __("LinkedIn"), + 'key' => 'li', + 'type' => 'TEXT', + 'size' => '4', + ], + + [ + 'title' => __("Youtube"), + 'key' => 'yt', + 'type' => 'TEXT', + 'size' => '4', + ], + [ + 'title' => __("Telegram"), + 'key' => 'tg', + 'type' => 'TEXT', + 'size' => '4', + ], + [ + 'title' => __('Under construction'), + 'key' => 'under', + 'type' => 'CHECKBOX', + 'value' => 0, + ], + + ], + 'SEO' => [ + [ + 'title' => __("Common keyword"), + 'key' => 'keyword', + 'type' => 'TEXT', + 'value' => 'shop,xshop, sale, xStack', + ], + [ + 'title' => __("Common description"), + 'key' => 'desc', + 'type' => 'TEXT', + 'value' => 'Best customizable shop in the world', + ], + [ + 'title' => __("Google Webmaster code"), + 'key' => 'google-webmaster-code', + 'type' => 'CODE', + ], + [ + 'title' => __("SEO image"), + 'key' => 'site_image', + 'type' => 'FILE', + ], + ], + 'Media' => [ + [ + 'title' => __("Logo (svg)"), + 'key' => 'logo_svg', + 'type' => 'FILE', + ], + [ + 'title' => __("Logo (png)"), + 'key' => 'logo_png', + 'type' => 'FILE', + ], + [ + 'title' => __('Optimize type'), + 'key' => 'optimize', + 'type' => 'TEXT', + 'value' => 'webp', + 'size' => '6', + ], + [ + 'title' => __('Watermark'), + 'key' => 'watermark', + 'type' => 'CHECKBOX', + 'value' => false, + 'size' => '6', + ], + [ + 'title' => __('Product thumbnail size'), + 'key' => 'product_image', + 'type' => 'TEXT', + 'value' => '1200x1200', + 'size' => '6', + ], + [ + 'title' => __('Product image size'), + 'key' => 'product_thumb', + 'type' => 'TEXT', + 'value' => '500x500', + 'size' => '6', + ], + [ + 'title' => __('Post thumbnail size'), + 'key' => 'post_thumb', + 'type' => 'TEXT', + 'value' => '500x500', + 'size' => '6', + ], + [ + 'title' => __('Gallery thumbnail size'), + 'key' => 'gallery_thumb', + 'type' => 'TEXT', + 'value' => '500x500', + 'size' => '6', + ], + ] + ]; + foreach ($sections as $section => $section_data) { + foreach ($section_data as $set) { + + $setting = new Setting(); + $setting->title = $set['title']; + $setting->section = $section; + $setting->key = $set['key']; + $setting->value = $set['value']??null; + $setting->type = $set['type']??'TEXT'; + $setting->ltr = $set['ltr']??false; + $setting->is_basic = true; + $setting->size = $set['size']??12;; + $setting->save(); + } + } } } diff --git a/public/upload/images/logo.png b/public/upload/images/logo.png new file mode 100644 index 0000000..bac62e8 Binary files /dev/null and b/public/upload/images/logo.png differ diff --git a/public/upload/images/logo.svg b/public/upload/images/logo.svg new file mode 100644 index 0000000..d114efc --- /dev/null +++ b/public/upload/images/logo.svg @@ -0,0 +1,153 @@ + + + + diff --git a/resources/js/app.js b/resources/js/app.js index 9ce72cd..a1693d9 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -24,6 +24,7 @@ import './panel/general-events.js'; import './panel/editor-handle.js'; import './panel/step-controller.js'; import './panel/product-upload-controller.js'; +import './panel/setting-section-controller.js'; /** * Next, we will create a fresh Vue application instance. You may then begin diff --git a/resources/js/panel/setting-section-controller.js b/resources/js/panel/setting-section-controller.js new file mode 100644 index 0000000..8858bd1 --- /dev/null +++ b/resources/js/panel/setting-section-controller.js @@ -0,0 +1,59 @@ +document.addEventListener('DOMContentLoaded', function () { + // Get all section group items + let sectionGroupItems = document.querySelectorAll('.section-group-item'); + + // Get all sections + let sections = document.querySelectorAll('#setting-sections section'); + + // Hide all sections initially + sections?.forEach(section => { + section.style.display = 'none'; + }); + + + // Show/hide sections on click + sectionGroupItems?.forEach(item => { + item.addEventListener('click', function (event) { + try { + + event.preventDefault(); + let targetId = this.getAttribute('href').slice(1); + sections.forEach(section => { + if (section.id === targetId) { + section.style.display = 'block'; + } else { + section.style.display = 'none'; + } + }); + sectionGroupItems.forEach(link => { + link.classList.remove('active'); + }); + this.classList.add('active'); + + } catch (e) { + console.log(e.message); + } + + }); + }); + + // Show section based on hash in URL + let hash = window.location.hash.slice(1); + if (hash) { + sections.forEach(section => { + if (section.id === hash) { + section.style.display = 'block'; + } else { + section.style.display = 'none'; + } + }); + } + + + try { + // Show the first section on page load + document.querySelector('.section-group-item').dispatchEvent(new Event('click')); + } catch (e) { + } + +}); diff --git a/resources/sass/panel/_common.scss b/resources/sass/panel/_common.scss index 79963f2..03752f7 100644 --- a/resources/sass/panel/_common.scss +++ b/resources/sass/panel/_common.scss @@ -128,3 +128,33 @@ a.btn,a.action-btn,a.circle-btn{ z-index: 1; margin-bottom: -75px; } + +.section-group{ + + .section-group-item{ + display: block; + padding: .5rem; + background: #ffffff11; + border-bottom: 1px solid #00000022; + color: white; + &.active{ + background: $primary-color-panel; + } + + &:hover{ + background: rgba($primary-color-panel,.7); + } + } +} + +#setting-sections{ + section{ + display: none; + background: $lighter-color; + padding: 1rem; + + .setting-field{ + padding: 5px; + } + } +} diff --git a/resources/views/admin/attachments/attachment-form.blade.php b/resources/views/admin/attachments/attachment-form.blade.php index e8df046..e6f73cc 100644 --- a/resources/views/admin/attachments/attachment-form.blade.php +++ b/resources/views/admin/attachments/attachment-form.blade.php @@ -21,7 +21,7 @@
  • {{__("If you want to only attach to other staff members and do not want to appear in the website attachment list, uncheck `fillable`")}}
  • - @if($item->file == null) + @if(isset($item) && $item->file == null)
  • {{__("There is noting file to show!")}}
  • @@ -32,7 +32,7 @@ - @if($item) + @if(isset($item))

    diff --git a/resources/views/admin/commons/setting.blade.php b/resources/views/admin/commons/setting.blade.php new file mode 100644 index 0000000..6741235 --- /dev/null +++ b/resources/views/admin/commons/setting.blade.php @@ -0,0 +1,139 @@ +@extends('layouts.app') +@section('title') + {{__("Setting")}} - +@endsection +@section('content') +
    +
    +
    + {{-- list side bar start--}} +
    + @include('components.err') +
    +

    + + {{__("Tips")}} +

    +
      +
    • + {{__("Recommends")}} +
    • +
    +
    + +
    +

    + + {{__("Sections")}} +

    +
    + +
    + @foreach(\App\Models\Setting::groupBy('section')->pluck('section')->toArray() as $sec) + + {{$sec}} + + @endforeach +
    +
    +
    +
    +

    + + {{__("Add new setting")}} +

    + @if(auth()->user()->hasRole('developer')) +
    + @csrf +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    +
    + + +
    + + + +
    + + @endif +
    + + +
    +
    +
    + @csrf + @foreach(\App\Models\Setting::groupBy('section')->pluck('section')->toArray() as $sec) +
    +
    + @foreach($settings as $setting) + @if($setting->section == $sec) + @include('components.setting-field') + @endif + @endforeach +
    +
    + @endforeach + +
    +
    +
    +   +
    +
    +
    +@endsection diff --git a/resources/views/admin/products/sub-pages/product-step2.blade.php b/resources/views/admin/products/sub-pages/product-step2.blade.php index cb1fd1b..ff54f26 100644 --- a/resources/views/admin/products/sub-pages/product-step2.blade.php +++ b/resources/views/admin/products/sub-pages/product-step2.blade.php @@ -17,7 +17,7 @@ @foreach($item->getMedia() as $k => $media)
    - {{$k}} + {{$k}}
    diff --git a/resources/views/components/panel-side-navbar.blade.php b/resources/views/components/panel-side-navbar.blade.php index 5a3abe6..3cbc827 100644 --- a/resources/views/components/panel-side-navbar.blade.php +++ b/resources/views/components/panel-side-navbar.blade.php @@ -216,7 +216,7 @@
  • - +
  • diff --git a/resources/views/components/setting-field.blade.php b/resources/views/components/setting-field.blade.php new file mode 100644 index 0000000..13ef30f --- /dev/null +++ b/resources/views/components/setting-field.blade.php @@ -0,0 +1,102 @@ +
    + + + @switch($setting->type) + @case('LONGTEXT') + + @break + @case('CODE') + + @break + @case('EDITOR') + + @break + @case('CHECKBOX') + + @break + @case('CATEGORY') + + @break + @case('GROUP') + + @break + @case('FILE') +
    + @php($ext = strtolower(pathinfo(str_replace('_','.',$setting->key), PATHINFO_EXTENSION))) +
    + +
    + @if(!in_array($ext, ['svg','jpg','png','gif','webp'] ) ) +
    + + + +
    + @endif +
    + @if($ext == 'mp4') + +
    + @elseif($ext == 'mp3') + +
    + @elseif(in_array($ext, ['svg','jpg','png','gif','webp'] ) ) + {{$setting->key}} + @endif +
    + +
    + @break + @default + @if($setting->key == 'optimize') + + @else + ltr) dir="ltr" @endif> + @endif + @endswitch + +
    diff --git a/routes/web.php b/routes/web.php index dde1bd9..a89c0f4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -254,6 +254,15 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group( Route::post('update/{item}', [\App\Http\Controllers\Admin\AddressController::class, 'update'])->name('update'); Route::get('destroy/{item}', [\App\Http\Controllers\Admin\AddressController::class, 'destroy'])->name('destroy'); }); + + Route::prefix('setting')->name('setting.')->group( + function () { + Route::get('index', [\App\Http\Controllers\Admin\SettingController::class, "index"])->name('index'); + Route::post('store', [\App\Http\Controllers\Admin\SettingController::class, "store"])->name('store'); + Route::post('update', [\App\Http\Controllers\Admin\SettingController::class, "update"])->name('update'); + } + ); + }); });