json([ 'keys' => Feature::keys(), 'labels' => Feature::labels(), ]); } public function cawangan() { $cawangan = Cawangan::on('mysql7') ->orderBy('kodcaw') ->get(['kodcaw', 'details_caw']); $maps = Feature::mapForMany($cawangan->pluck('kodcaw')->all()); $data = $cawangan->map(function ($c) use ($maps) { return [ 'kodcaw' => $c->kodcaw, 'details_caw' => $c->nama_cawangan, 'features' => $maps[$c->kodcaw] ?? Feature::defaults(), ]; }); return response()->json($data); } public function update($kodcaw, $feature, Request $request) { $cawangan = Cawangan::on('mysql7')->where('kodcaw', $kodcaw)->first(); if (!$cawangan) { return response()->json(['message' => 'Cawangan tidak dijumpai'], 404); } if (!in_array($feature, Feature::keys(), true)) { return response()->json(['message' => 'Ciri tidak sah'], 422); } $enabled = (int) $request->input('enabled') ? 1 : 0; Feature::setEnabled($kodcaw, $feature, $enabled); return response()->json([ 'kodcaw' => $kodcaw, 'feature' => $feature, 'enabled' => $enabled, 'features' => Feature::mapFor($kodcaw), ]); } }