56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Superuser;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Support\Prototype\SuperuserData;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Str;
|
|
|
|
class PengaturanController extends Controller
|
|
{
|
|
public function show(Request $request): View
|
|
{
|
|
$tabs = SuperuserData::pengaturan();
|
|
$tab = (string) $request->query('tab');
|
|
|
|
if (! isset($tabs[$tab])) {
|
|
$tab = array_key_first($tabs);
|
|
}
|
|
|
|
return view('superuser.pengaturan.index', ['tabs' => $tabs, 'tab' => $tab]);
|
|
}
|
|
|
|
/** Tahap tampilan: formulir hanya divalidasi, belum disimpan. */
|
|
public function update(Request $request): RedirectResponse
|
|
{
|
|
$tabs = SuperuserData::pengaturan();
|
|
$tab = (string) $request->input('tab');
|
|
abort_unless(isset($tabs[$tab]), 404);
|
|
|
|
$rules = [];
|
|
$names = [];
|
|
$checkboxes = [];
|
|
|
|
foreach ($tabs[$tab]['fields'] as $field) {
|
|
if ($field['type'] === 'checkbox') {
|
|
$checkboxes[$field['name']] = $request->boolean($field['name']);
|
|
$rules[$field['name']] = ['boolean'];
|
|
} else {
|
|
$rules[$field['name']] = $field['rules'];
|
|
}
|
|
$names[$field['name']] = Str::lower($field['label']);
|
|
}
|
|
|
|
$request->merge($checkboxes);
|
|
$request->validate($rules, [], $names);
|
|
|
|
$label = Str::lower($tabs[$tab]['label']);
|
|
|
|
return redirect()->route('superuser.pengaturan', ['tab' => $tab])
|
|
->with('info', "Pengaturan {$label} berhasil divalidasi. Tampilan prototipe: perubahan belum disimpan karena basis data belum dibangun.");
|
|
}
|
|
}
|