0) { foreach($data[1] as $key=>$attr) { // $params 에서 찾기 if(isset($params[$attr])) { $args[$key] = $params[$attr]; } // 모델에서 찾기 if(property_exists($model, $attr)) { $args[$key] = $model->{$attr}; } // request 에서 찾기 if(request()->has($attr)) { $args[$key] = request()->get($attr, ''); } } } return route($data[0], $args); } return route($data); }; $htmls = []; if(property_exists($model, 'form')) { $form = $model->form; $htmls[] = FormFacade::model($model, ['id'=>'form', 'route'=>$form['action'], 'files' => true]); $inputs = $model->inputs; $rows = []; foreach($inputs as $name => $element) { $rowHtml = []; $rowHtml['label'] = ''; $rowHtml['html'] = ''; // hidden if($name == '#') { $rowHtml['hidden'] = $element; $rows[] = $rowHtml; continue; } // custom view else if(Str::startsWith($name, '@')) { $rowHtml['view'] = $element; $rows[] = $rowHtml; continue; } $type = 'text'; if(isset($element['type'])) $type = $element['type']; $rowHtml['label'] = FormFacade::label($name, $element['label']); if($type == 'text') $rowHtml['html'] = FormFacade::text($name, null, array_merge(['class'=>'form-control'], isset($element['attrs'])?$element['attrs']:[])); else if($type == 'textarea') $rowHtml['html'] = FormFacade::textarea($name, null, array_merge(['class'=>'form-control'], isset($element['attrs'])?$element['attrs']:[])); else if($type == 'select') $rowHtml['html'] = FormFacade::select($name, $element['data'], null, array_merge(['class'=>'form-control'], isset($element['attrs'])?$element['attrs']:[])); else if($type == 'radio') { $radioLables = []; $radioHtmls = []; if(isset($element['data'])) { $no = 0; foreach($element['data'] as $value => $text) { $id = $name.'-'.($no++); $radioLables[] = FormFacade::label($id, $text, ['class'=>'custom-control-label']); $radioHtmls[] = FormFacade::radio($name, $value, null, array_merge(['id'=>$id, 'class'=>'custom-control-input'], isset($element['attrs'])?$element['attrs']:[])); } } $radioHtml = []; foreach($radioLables as $index=>$label) { $radioHtml[] = sprintf('
%s%s
', $radioHtmls[$index], $label); } $rowHtml['html'] = sprintf('
%s
', implode("", $radioHtml)); } else if($type == 'file') $rowHtml['html'] = sprintf('
%s
', FormFacade::file($name, ['class'=>'custom-file-input'])); $rows[] = $rowHtml; } $inputHtml = []; foreach($rows as $row) { if(isset($row['hidden'])) { foreach($row['hidden'] as $hidden) { $inputHtml[] = FormFacade::hidden($hidden); } } else if(isset($row['view'])) $inputHtml[] = view($row['view'], array_merge(['data' => $model], $params))->render(); else $inputHtml[] = sprintf('
%s%s
', $row['label'], $row['html']); } $htmls[] = implode("\n", $inputHtml); $buttonText = '저장'; if($model->id > 0) $buttonText = '수정'; $buttons = []; if(isset($form['list'])) $buttons[] = sprintf('
목록
', $funcGeneaterRoute($model, $form['list'])); else $buttons[] = '
'; $buttons[] = sprintf('
%s
', FormFacade::button($buttonText, ['type'=>'submit', 'class'=>'btn btn-primary waves-effect waves-themed'])); if(isset($form['delete'])) $buttons[] = sprintf('
삭제
', $funcGeneaterRoute($model, $form['delete'])); else $buttons[] = '
'; $htmls[] = sprintf('
%s
', implode("\n", $buttons) ); $htmls[] = FormFacade::close(); } return new HtmlString( implode("\n", $htmls) ); }); } /** * Register any application services. * * @return void */ public function register() { // } }