2017-11-30 2 views
0

여기 까다로운 상황이 있습니다.Laravel 양식 - 여러 채우기 입력보기

색인을 편집 할 때 기존 값을 채울 수있는 편집 양식이 있습니다. (나는 컨트롤러에서 모델 객체를 전달한다). 그것은 모든 입력 필드에 대해 작동하지만, 어떻게 해야할지 모르는 특정 다중 선택 필드를 채워야합니다. 나는 객체에서이 특정 값을 전달하려고 시도했다. 배열 (각각의 선택 가능한 값의 ID를 포함하고있다)은 뷰를 파손 시키거나 json_encode를 사용하는 json 문자열이다. 나는 사람이이 일을 완수하는 곳에서 기사를 읽었지 만 다 대다 관계 표로 끝났지 만 채우기 위해 필요한 값은 표에서 나오지 않는다.

결과 객체를 사용 DD()

Contact {#408 ▼ 
    +table: "contacts" 
    #dates: array:1 [▼ 
    0 => "deleted_at" 
    ] 
    +fillable: array:5 [▼ 
    0 => "nombre" 
    1 => "apellido" 
    2 => "cargo" 
    3 => "empresa_id" 
    4 => "groups" 
    ] 
    #casts: array:5 [▼ 
    "nombre" => "string" 
    "apellido" => "string" 
    "cargo" => "string" 
    "empresa_id" => "integer" 
    "groups" => "array" 
    ] 
    #connection: null 
    #primaryKey: "id" 
    #keyType: "int" 
    #perPage: 15 
    +incrementing: true 
    +timestamps: true 
    #attributes: array:9 [▼ 
    "id" => 4 
    "nombre" => "redacted" 
    "apellido" => "redacted" 
    "cargo" => "redacted" 
    "empresa_id" => 2 
    "created_at" => "2017-03-09 20:30:19" 
    "updated_at" => "2017-11-29 17:30:55" 
    "deleted_at" => null 
    "groups" => "["2","3","4"]" 
    ] 
    #original: array:9 [▼ 
    "id" => 4 
    "nombre" => "redacted" 
    "apellido" => "redacted" 
    "cargo" => "redacted" 
    "empresa_id" => 2 
    "created_at" => "2017-03-09 20:30:19" 
    "updated_at" => "2017-11-29 17:30:55" 
    "deleted_at" => null 
    "groups" => "["2","3","4"]" 
    ] 
    #relations: [] 
    #hidden: [] 
    #visible: [] 
    #appends: [] 
    #guarded: array:1 [▼ 
    0 => "*" 
    ] 
    #dateFormat: null 
    #touches: [] 
    #observables: [] 
    #with: [] 
    +exists: true 
    +wasRecentlyCreated: false 
    #forceDeleting: false 

다중 선택 양식.

{!! Form::label('groups', 'Grupos:') !!} </br> 
{!! Form::select('groups', $groups, null, ['data-actions-box' => 'true', 'multiple'=>'multiple']) !!} 

자세한 정보가 필요하면 질문을 편집합니다.

답변

0

으로 배열 요소를 변환하여 json_encode에 전달하는 문제를 해결했습니다.