From 4621547c010077891a27a92c6a6c79da36be59f9 Mon Sep 17 00:00:00 2001 From: IceToast Date: Sat, 15 Jan 2022 00:49:33 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Allow=20value=20column=20in?= =?UTF-8?q?=20table=20to=20be=20nullable=20->=20can=20store=20"0"=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Classes/Settings/Invoices.php | 6 ++-- app/Classes/Settings/Language.php | 6 ++-- app/Classes/Settings/Payments.php | 6 ++-- ...8_update_settings_table_allow_nullable.php | 34 +++++++++++++++++++ .../views/admin/settings/index.blade.php | 25 +++++++------- .../views/admin/settings/tabs/misc.blade.php | 15 ++++---- .../admin/settings/tabs/system.blade.php | 4 +-- resources/views/layouts/main.blade.php | 25 +++++++------- 8 files changed, 74 insertions(+), 47 deletions(-) create mode 100644 database/migrations/2022_01_14_234418_update_settings_table_allow_nullable.php diff --git a/app/Classes/Settings/Invoices.php b/app/Classes/Settings/Invoices.php index 4cca06b5..b19bb6e3 100644 --- a/app/Classes/Settings/Invoices.php +++ b/app/Classes/Settings/Invoices.php @@ -33,9 +33,7 @@ class Invoices foreach ($values as $key => $value) { $param = $request->get($value); - if (!$param) { - $param = ""; - } + Settings::where('key', $key)->updateOrCreate(['key' => $key], ['value' => $param]); Cache::forget("setting" . ':' . $key); } @@ -46,6 +44,6 @@ class Invoices } - return redirect(route('admin.settings.index') . '#invoices')->with('success', 'Invoice settings updated!'); + return redirect(route('admin.settings.index') . '#invoices')->with('success', __('Invoice settings updated!')); } } diff --git a/app/Classes/Settings/Language.php b/app/Classes/Settings/Language.php index 55818b1d..1d59614a 100644 --- a/app/Classes/Settings/Language.php +++ b/app/Classes/Settings/Language.php @@ -30,15 +30,13 @@ class Language foreach ($values as $key => $value) { $param = $request->get($value); - if (!$param) { - $param = "false"; - } + Settings::where('key', $key)->updateOrCreate(['key' => $key], ['value' => $param]); Cache::forget("setting" . ':' . $key); Session::remove("locale"); } - return redirect(route('admin.settings.index') . '#language')->with('success', 'Language settings updated!'); + return redirect(route('admin.settings.index') . '#language')->with('success', __('Language settings updated!')); } } diff --git a/app/Classes/Settings/Payments.php b/app/Classes/Settings/Payments.php index 7442f2b8..2accf807 100644 --- a/app/Classes/Settings/Payments.php +++ b/app/Classes/Settings/Payments.php @@ -35,14 +35,12 @@ class Payments foreach ($values as $key => $value) { $param = $request->get($value); - if (!$param) { - $param = ""; - } + Settings::where('key', $key)->updateOrCreate(['key' => $key], ['value' => $param]); Cache::forget("setting" . ':' . $key); } - return redirect(route('admin.settings.index') . '#payment')->with('success', 'Payment settings updated!'); + return redirect(route('admin.settings.index') . '#payment')->with('success', __('Payment settings updated!')); } } diff --git a/database/migrations/2022_01_14_234418_update_settings_table_allow_nullable.php b/database/migrations/2022_01_14_234418_update_settings_table_allow_nullable.php new file mode 100644 index 00000000..20d5a0c9 --- /dev/null +++ b/database/migrations/2022_01_14_234418_update_settings_table_allow_nullable.php @@ -0,0 +1,34 @@ +string('value')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + //disallow value column in settings table to be nullable + Schema::table('settings', function (Blueprint $table) { + $table->string('value')->nullable(false)->change(); + }); + } +} diff --git a/resources/views/admin/settings/index.blade.php b/resources/views/admin/settings/index.blade.php index 54c17954..5941c483 100644 --- a/resources/views/admin/settings/index.blade.php +++ b/resources/views/admin/settings/index.blade.php @@ -73,20 +73,19 @@ var fileName = $(this).val().split("\\").pop(); $(this).siblings(".custom-file-label").addClass("selected").html(fileName); }); - - const tabPaneHash = window.location.hash; - if (tabPaneHash) { - $('.nav-tabs a[href="' + tabPaneHash + '"]').tab('show'); - } - - $('.nav-tabs a').click(function(e) { - $(this).tab('show'); - const scrollmem = $('body').scrollTop(); - window.location.hash = this.hash; - $('html,body').scrollTop(scrollmem); - }); - }) + + const tabPaneHash = window.location.hash; + if (tabPaneHash) { + $('.nav-tabs a[href="' + tabPaneHash + '"]').tab('show'); + } + + $('.nav-tabs a').click(function(e) { + $(this).tab('show'); + const scrollmem = $('body').scrollTop(); + window.location.hash = this.hash; + $('html,body').scrollTop(scrollmem); + }); diff --git a/resources/views/admin/settings/tabs/misc.blade.php b/resources/views/admin/settings/tabs/misc.blade.php index 74ba7aee..623ef94b 100644 --- a/resources/views/admin/settings/tabs/misc.blade.php +++ b/resources/views/admin/settings/tabs/misc.blade.php @@ -88,20 +88,19 @@
- - {{ __('ReCaptcha Site-Key') }}: + + class="form-control @error('recaptcha-site-key') is-invalid @enderror">
- - + +
diff --git a/resources/views/admin/settings/tabs/system.blade.php b/resources/views/admin/settings/tabs/system.blade.php index 60ed8c13..b8fc58a3 100644 --- a/resources/views/admin/settings/tabs/system.blade.php +++ b/resources/views/admin/settings/tabs/system.blade.php @@ -103,14 +103,14 @@
-
- diff --git a/resources/views/layouts/main.blade.php b/resources/views/layouts/main.blade.php index 072ef13a..2593f34f 100644 --- a/resources/views/layouts/main.blade.php +++ b/resources/views/layouts/main.blade.php @@ -32,6 +32,7 @@ + @@ -49,8 +50,8 @@ class="fas fa-home mr-2">{{ __('Home') }} @if (config('SETTINGS::LOCALE:CLIENTS_CAN_CHANGE') == 'true') @@ -390,7 +391,7 @@ {{-- --}} {{-- --}} - + @@ -404,17 +405,17 @@ - +