public function responseEdit($id) { $response = parent::responseEdit($id); $validation = $response['validation']; unset($response['validation']); $role = Role::find($id); $menus = Menu::ofParent(null)->sort()->get(); $response['role'] = $role; $response['menus'] = $menus; if ($response['initial'] == true) { // Pas form baru kebuka $response['errors'] = []; foreach ($this->validations as $f => $v) { $fields[$f] = $role->{$f}; if (is_a($fields[$f], 'Illuminate\\Support\\Collection')) { $fields[$f] = $fields[$f]->toArray(); } } foreach ($fields['permissions'] as $f) { $sx = explode(',', $f['privileges']); foreach ($sx as $ff) { $fields['permissions[' . $f['menu_id'] . '][' . strtolower($ff) . ']'] = 'on'; } } $response['fields'] = $fields; // dd($fields); $response['output'] = view('backend.pages.security.roles.form-ajax', $response)->render(); } elseif ($validation->passes()) { // Pas validasi berhasil $data = $this->normaliseData($response['data']); // dd($data); Role::addOrModify($data, $id); $response['status'] = true; } else { // Pas validasi gagal $response['fields'] = $response['data']; $response['fields']['label'] = $role->label; $response['output'] = view('backend.pages.security.roles.form-ajax', $response)->render(); } return $response; }