grid Laavel-admin 지원 form
                                            
                                                
                                                
                                                
                                                
                                                
                                                 14635 단어  PHPLaravellaravel-admin
                    
ver1.7.6 "Form Layout"구현
https://laravel-admin.org/docs/#/en/model-form-layout
(2019-08-14 추기)
Laravel-admin v1.7.3(2019-07-22)이면 우리의 방법이 순조롭지 못하다.
개요
Row가 제 생각대로 역할을 하지 않아서 제 힘으로 이뤘어요
완성되면 이런 느낌이에요.
 
 탭과 HasMany에 깊이 들어가도 정상적으로 작동할 수 있습니다.
 
 설치 방법
1. App/Admin/Extensions에서 다음 파일을 구성합니다.
MultipleColumn.php
<?php
namespace App\Admin\Extensions;
use Encore\Admin\Form;
use Encore\Admin\Form\Field;
class MultipleColumn extends Field
{
    protected $label;
    /**
     * Callback for add field to current row.s.
     *
     * @var \Closure
     */
    protected $callback;
    /**
     * Parent form.
     *
     * @var Form
     */
    protected $form;
    /**
     * Fields in this row.
     *
     * @var array
     */
    protected $fields = [];
    /**
     * Default field width for appended field.
     *
     * @var int
     */
    protected $defaultFieldWidth = 12;
    protected $view = 'form.multiplecolumn';
    public function __construct($label, $arguments = [])
    {
        $this->label = $label;
        $this->callback = $arguments[0];
        $this->form = $arguments[1];
        call_user_func($this->callback, $this);
    }
    /**
     * Set width for a incomming field.
     *
     * @param int $width
     *
     * @return $this
     */
    public function width($width = 12)
    {
        $this->defaultFieldWidth = $width;
        return $this;
    }
    public function render()
    {
        return parent::render($this->view)->with([
            'fields' => $this->fields,
            'label' => $this->label,
        ]);
    }
    /**
     * Add field.
     *
     * @param string $method
     * @param array  $arguments
     *
     * @return Field|void
     */
    public function __call($method, $arguments)
    {
        $field = $this->form->__call($method, $arguments);
        $this->fields[] = [
            'width'   => $this->defaultFieldWidth,
            'element' => $field,
        ];
        return $field;
    }
}
use App\Admin\Extensions\MultipleColumn;
Encore\Admin\Form::extend('multipleColumn', MultipleColumn::class);
multiplecolumn.blade.php
@php
    $rand = mt_rand();
@endphp
<div class="form-group  multiColumn{{ $rand }}">
        <label class="col-sm-2 control-label">{{$label}}</label>
        @foreach($fields as $field)
            <div class="col-sm-{{ $field['width'] }}">
                {!! $field['element']->render() !!}
            </div>
        @endforeach
</div>
<script>
    for (var i=0; i<{{ count($fields) }}; i++) {
        $('.multiColumn{{ $rand }} ').prev().remove();
        $('.multiColumn{{ $rand }} .form-group').css('margin-bottom','initial');
    }
</script>
사용법
$form->multipleColumn('郵便番号',function ($column){
  $column->width(2)
         ->text('postal_code','')
         ->rules('digits:7', ['digits' => '7桁の数字を入力してください'])
         ->placeholder('郵便番号')
         ->setWidth(12,0);
  $column->width(5)
         ->select('prefucture','都道府県')
         ->placeholder('都道府県')
         ->options(config('pref'))
         ->setWidth(3,2);
},$form);
$form->multipleColumn('住所',function ($column){
  $column->width(4)
         ->text('address1','')
         ->placeholder('住所1')
       ->setWidth(12,0);
  $column->width(4)
         ->text('address2','')
         ->placeholder('住所2(マンション名・ビル名など)')
         ->setWidth(12,0);
},$form);
form-group은 이중으로 생성된 것으로 js로 강제로 삭제된 곳은miso입니다
(원래 이중생성을 피하려고 했다)
Reference
이 문제에 관하여(grid Laavel-admin 지원 form), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/akimats/items/acd24cc5e32a0eac979e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)