/** * @param $section * @return \Illuminate\View\View */ public function edit($section) { $default = config('administrator-settings.default')[$section]; $form = FormBuilder\create_form(['action' => route('update_setting', ['section' => $section]), 'method' => FormBuilder\Form::METHOD_POST]); $settings = $this->getRepository()->all($section); $settings = $section == 'general' ? isset($settings['general']) ? $settings['general'] : [] : $settings; array_walk($default['items'], function ($value, $key) use(&$form, $settings) { if (!$this->isAllowed(isset($value['roles']) ? $value['roles'] : [], isset($value['permissions']) ? $value['permissions'] : [])) { return false; } $attributes = ['name' => $value['key'], 'value' => isset($settings[$value['key']]) ? $settings[$value['key']] : (isset($value['value']) ? $value['value'] : '')]; $type = isset($value['type']) ? $value['type'] : 'text'; if ($type == 'checkbox') { $form->addElement($key . '1', FormBuilder\element_hidden('', ['value' => 0, 'group' => $value['group']] + $attributes), true); } $form->addElement($key, FormBuilder\get_element($type, $attributes + $value), true); }); return view('scaffold::scaffold.edit', compact('form')); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $mailRow = $this->repository->find($id); if (!$_POST) { $form = FormBuilder\create_form(['action' => route('admin.mail.edit', ['id' => $id]), 'method' => FormBuilder\Form::METHOD_POST]); $elements[] = FormBuilder\element_text('slug', ['name' => 'slug', 'group' => 'default', 'value' => isset($mailRow->slug) ? $mailRow->slug : '']); if ($mailRow instanceof Translatable) { $locales = Locale\get_locales(); foreach ($locales as $locale => $attributes) { $translation = $mailRow->translate($locale); foreach ($mailRow->translatedAttributes() as $attribute => $type) { $elements[] = FormBuilder\get_element($type, ['group' => 'translations', 'label' => ucfirst($attribute) . ' ' . $locale, 'value' => isset($translation[$attribute]) ? $translation[$attribute] : '', 'name' => $locale . '[' . $attribute . ']']); } } } $form->addElements($elements, true); return view('scaffold::scaffold.edit', compact('form')); } $mailRow->fill($_POST)->save(); return back(); }