middleware(['auth', 'admin']); } protected function api() { return Http::withOptions(['verify' => config('app.api_verify')]); } public function index() { $api_url = config('api.url'); $metaRes = $this->api()->get($api_url . '/api/features'); $meta = $metaRes->successful() ? $metaRes->json() : []; $keys = is_array($meta) && !empty($meta['keys']) ? $meta['keys'] : ['pembiayaan_online']; $labels = is_array($meta) && !empty($meta['labels']) ? $meta['labels'] : [ 'pembiayaan_online' => 'Pembiayaan Online', ]; $listRes = $this->api()->get($api_url . '/api/features/cawangan'); $cawangan = ($listRes->successful() && is_array($listRes->json())) ? $listRes->json() : []; if (!$listRes->successful()) { session()->now('error', 'Gagal muat senarai ciri cawangan.'); } return view('admin.features', compact('api_url', 'keys', 'labels', 'cawangan')); } public function update(Request $request) { $kodcaw = trim((string) $request->input('kodcaw', '')); $feature = trim((string) $request->input('feature', '')); $enabled = (int) $request->input('enabled') ? 1 : 0; if ($kodcaw === '' || $feature === '') { return redirect()->route('admin.features')->with('error', 'Kod cawangan dan ciri diperlukan.'); } $res = $this->api() ->put(config('api.url') . '/api/features/' . $kodcaw . '/' . $feature, [ 'enabled' => $enabled, ]); if (!$res->successful()) { $body = $res->json(); $msg = is_array($body) && isset($body['message']) ? $body['message'] : 'Gagal kemaskini ciri cawangan.'; return redirect()->route('admin.features')->with('error', $msg); } $label = $enabled ? 'diaktifkan' : 'dinyahaktifkan'; return redirect() ->route('admin.features') ->with('message', $feature . ' ' . $label . ' untuk ' . $kodcaw . '.'); } }