feat: ✨ Add Settings update route & Validation functionality
This commit is contained in:
parent
20f0e1dfc2
commit
c3420b1684
4 changed files with 125 additions and 68 deletions
|
@ -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.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -62,80 +62,110 @@
|
|||
<!-- /.sidebar-menu -->
|
||||
<!-- Content in $settings -->
|
||||
<div class="col-10 p-0">
|
||||
|
||||
<div class="tab-content ml-3" style="width: 100%;">
|
||||
@foreach ($settings as $category => $options)
|
||||
<div container class="tab-pane fade container {{ $loop->first ? 'active show' : '' }}"
|
||||
id="{{ $category }}" role="tabpanel">
|
||||
@foreach ($options as $key => $value)
|
||||
<div class="row">
|
||||
<div class="col-4 d-flex align-items-center">
|
||||
<label for="{{ $key }}">{{ $value['label'] }}</label>
|
||||
</div>
|
||||
|
||||
<div class="col-8">
|
||||
<div class="custom-control mb-3 d-flex align-items-center">
|
||||
@if ($value['description'])
|
||||
<i class="fas fa-info-circle mr-4" data-toggle="popover"
|
||||
data-trigger="hover" data-placement="top" data-html="true"
|
||||
data-content="{{ $value['description'] }}"></i>
|
||||
@else
|
||||
<i class="fas fa-info-circle mr-4 invisible"></i>
|
||||
@endif
|
||||
<form action="{{ route('admin.settings.update') }}" method="POST">
|
||||
@csrf
|
||||
@method('POST')
|
||||
|
||||
@switch($value)
|
||||
@case($value['type'] == 'string')
|
||||
<input type="text" class="form-control"
|
||||
name="{{ $key }}" value="{{ $value['value'] }}">
|
||||
@break
|
||||
@foreach ($options as $key => $value)
|
||||
<input type="hidden" name="category" value="{{ $category }}">
|
||||
<div class="row">
|
||||
<div class="col-4 d-flex align-items-center">
|
||||
<label for="{{ $key }}">{{ $value['label'] }}</label>
|
||||
</div>
|
||||
|
||||
@case($value['type'] == 'boolean')
|
||||
<input type="checkbox" name="{{ $key }}"
|
||||
value="{{ $value['value'] }}">
|
||||
@break
|
||||
<div class="col-8">
|
||||
<div class="custom-control mb-3 d-flex align-items-center">
|
||||
@if ($value['description'])
|
||||
<i class="fas fa-info-circle mr-4" data-toggle="popover"
|
||||
data-trigger="hover" data-placement="top"
|
||||
data-html="true"
|
||||
data-content="{{ $value['description'] }}"></i>
|
||||
@else
|
||||
<i class="fas fa-info-circle mr-4 invisible"></i>
|
||||
@endif
|
||||
|
||||
@case($value['type'] == 'number')
|
||||
<input type="number" class="form-control"
|
||||
name="{{ $key }}" value="{{ $value['value'] }}">
|
||||
@break
|
||||
<div class=" w-100">
|
||||
@switch($value)
|
||||
@case($value['type'] == 'string')
|
||||
<input type="text" class="form-control"
|
||||
name="{{ $key }}"
|
||||
value="{{ $value['value'] }}">
|
||||
@break
|
||||
|
||||
@case($value['type'] == 'select')
|
||||
<select id="{{ $key }}" class="custom-select w-100"
|
||||
name="{{ $key }}">
|
||||
@foreach ($value['options'] as $option)
|
||||
<option value="{{ $option }}"
|
||||
{{ $value['value'] == $option ? 'selected' : '' }}>
|
||||
{{ __($option) }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@break
|
||||
@case($value['type'] == 'boolean')
|
||||
<input type="checkbox" name="{{ $key }}"
|
||||
value="{{ $value['value'] }}">
|
||||
@break
|
||||
|
||||
@case($value['type'] == 'multiselect')
|
||||
<select id="{{ $key }}" class="custom-select w-100"
|
||||
name="{{ $key }}" multiple>
|
||||
@foreach ($value['options'] as $option)
|
||||
<option value="{{ $option }}"
|
||||
{{ $value['value'] == $option ? 'selected' : '' }}>
|
||||
{{ __($option) }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@break
|
||||
@case($value['type'] == 'number')
|
||||
<input type="number" class="form-control"
|
||||
name="{{ $key }}"
|
||||
value="{{ $value['value'] }}">
|
||||
@break
|
||||
|
||||
@case($value['type'] == 'textarea')
|
||||
<textarea class="form-control" name="{{ $key }}" rows="3">{{ $value['value'] }}</textarea>
|
||||
@break
|
||||
@case($value['type'] == 'select')
|
||||
<select id="{{ $key }}"
|
||||
class="custom-select w-100" name="{{ $key }}">
|
||||
@foreach ($value['options'] as $option)
|
||||
<option value="{{ $option }}"
|
||||
{{ $value['value'] == $option ? 'selected' : '' }}>
|
||||
{{ __($option) }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@break
|
||||
|
||||
@default
|
||||
@endswitch
|
||||
@case($value['type'] == 'multiselect')
|
||||
<select id="{{ $key }}"
|
||||
class="custom-select w-100" name="{{ $key }}"
|
||||
multiple>
|
||||
@foreach ($value['options'] as $option)
|
||||
<option value="{{ $option }}"
|
||||
{{ $value['value'] == $option ? 'selected' : '' }}>
|
||||
{{ __($option) }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@break
|
||||
|
||||
@case($value['type'] == 'textarea')
|
||||
<textarea class="form-control" name="{{ $key }}" rows="3">{{ $value['value'] }}</textarea>
|
||||
@break
|
||||
|
||||
@default
|
||||
@endswitch
|
||||
@error($key)
|
||||
<div class="text-danger ">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-primary float-right">Save</button>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<button type="reset"
|
||||
class="btn btn-secondary float-right mr-2">Reset</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</form>
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue