From c3420b16844713ddb1513924d14438e594ffb89f Mon Sep 17 00:00:00 2001 From: IceToast Date: Fri, 10 Feb 2023 00:04:00 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Add=20Settings=20update=20r?= =?UTF-8?q?oute=20&=20Validation=20functionality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/SettingsController.php | 31 ++++ app/Settings/GeneralSettings.php | 6 +- routes/web.php | 14 +- .../views/admin/settings/index.blade.php | 142 +++++++++++------- 4 files changed, 125 insertions(+), 68 deletions(-) diff --git a/app/Http/Controllers/Admin/SettingsController.php b/app/Http/Controllers/Admin/SettingsController.php index 3136a92e..2f98830f 100644 --- a/app/Http/Controllers/Admin/SettingsController.php +++ b/app/Http/Controllers/Admin/SettingsController.php @@ -7,6 +7,9 @@ use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; use Illuminate\Http\Response; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Redirect; +use Illuminate\Support\Facades\Validator; use Qirolab\Theme\Theme; class SettingsController extends Controller @@ -61,4 +64,32 @@ class SettingsController extends Controller 'active_theme' => Theme::active(), ]); } + + /** + * Update the specified resource in storage. + * + */ + public function update(Request $request) + { + $category = request()->get('category'); + + error_log($category); + + + $className = 'App\\Settings\\' . $category . 'Settings'; + if (method_exists($className, 'getValidations')) { + $validations = $className::getValidations(); + } else { + $validations = []; + } + + + $validator = Validator::make($request->all(), $validations); + if ($validator->fails()) { + return Redirect::to('admin/settings' . '#' . $category)->withErrors($validator)->withInput(); + } + + + return Redirect::to('admin/settings' . '#' . $category)->with('success', 'Settings updated successfully.'); + } } diff --git a/app/Settings/GeneralSettings.php b/app/Settings/GeneralSettings.php index 4aac8bec..0225ab0c 100644 --- a/app/Settings/GeneralSettings.php +++ b/app/Settings/GeneralSettings.php @@ -34,14 +34,16 @@ class GeneralSettings extends Settings ]; } - public static function validation() + public static function getValidations() { // create validation rules that can be used in the controller return [ - 'main_site' => 'required|url', + 'main_site' => 'required|string|max:1', 'credits_display_name' => 'required|string', 'initial_user_credits' => 'required|numeric', 'initial_server_limit' => 'required|numeric', + 'recaptcha_enabled' => 'required|boolean', + ]; } diff --git a/routes/web.php b/routes/web.php index 61481945..438b4dd5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -113,7 +113,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () { Route::get('ticket/show/{ticket_id}', [TicketsController::class, 'show'])->name('ticket.show'); Route::post('ticket/reply', [TicketsController::class, 'reply'])->middleware(['throttle:ticket-reply'])->name('ticket.reply'); Route::post('ticket/close/{ticket_id}', [TicketsController::class, 'close'])->name('ticket.close'); - + //admin Route::prefix('admin')->name('admin.')->middleware('admin')->group(function () { @@ -165,13 +165,8 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () { Route::get('settings/checkPteroClientkey', [System::class, 'checkPteroClientkey'])->name('settings.checkPteroClientkey'); Route::redirect('settings#system', 'system')->name('settings.system'); - //settings - Route::patch('settings/update/invoice-settings', [Invoices::class, 'updateSettings'])->name('settings.update.invoicesettings'); - Route::patch('settings/update/language', [Language::class, 'updateSettings'])->name('settings.update.languagesettings'); - Route::patch('settings/update/payment', [Payments::class, 'updateSettings'])->name('settings.update.paymentsettings'); - Route::patch('settings/update/misc', [Misc::class, 'updateSettings'])->name('settings.update.miscsettings'); - Route::patch('settings/update/system', [System::class, 'updateSettings'])->name('settings.update.systemsettings'); - Route::resource('settings', SettingsController::class)->only('index'); + Route::get('settings', [SettingsController::class, 'index'])->name('settings.index'); + Route::post('settings', [SettingsController::class, 'update'])->name('settings.update'); //invoices Route::get('invoices/download-invoices', [InvoiceController::class, 'downloadAllInvoices'])->name('invoices.downloadAllInvoices'); @@ -221,8 +216,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () { Route::get('ticket/category/datatable', [TicketCategoryController::class, 'datatable'])->name('ticket.category.datatable'); - Route::resource("ticket/category", TicketCategoryController::class,['as' => 'ticket']); - + Route::resource("ticket/category", TicketCategoryController::class, ['as' => 'ticket']); }); Route::get('/home', [HomeController::class, 'index'])->name('home'); diff --git a/themes/default/views/admin/settings/index.blade.php b/themes/default/views/admin/settings/index.blade.php index 74f7a97d..6f49a97a 100644 --- a/themes/default/views/admin/settings/index.blade.php +++ b/themes/default/views/admin/settings/index.blade.php @@ -62,80 +62,110 @@
-
@foreach ($settings as $category => $options)
- @foreach ($options as $key => $value) -
-
- -
-
-
- @if ($value['description']) - - @else - - @endif +
+ @csrf + @method('POST') - @switch($value) - @case($value['type'] == 'string') - - @break + @foreach ($options as $key => $value) + +
+
+ +
- @case($value['type'] == 'boolean') - - @break +
+
+ @if ($value['description']) + + @else + + @endif - @case($value['type'] == 'number') - - @break +
+ @switch($value) + @case($value['type'] == 'string') + + @break - @case($value['type'] == 'select') - - @break + @case($value['type'] == 'boolean') + + @break - @case($value['type'] == 'multiselect') - - @break + @case($value['type'] == 'number') + + @break - @case($value['type'] == 'textarea') - - @break + @case($value['type'] == 'select') + + @break - @default - @endswitch + @case($value['type'] == 'multiselect') + + @break + + @case($value['type'] == 'textarea') + + @break + + @default + @endswitch + @error($key) +
+ {{ $message }} +
+ @enderror +
+ + +
+ @endforeach +
+
+ +
+
+ + +
- @endforeach +
@endforeach +