2017-08-08 32 views
0

母體刀片模板工作:表單模型結合不被內部部分

@extends('layouts.master') 

@section('content') 

<div class="panel-body"> 
    @if(count($errors)) 
     @include('common.errors') 
    @endif 

    {!! Form::model($entry, ['method' => $method, 'class' => 'form-horizontal', 'route' => [$route]]) !!} 


    @section('fields') 
     @foreach (['title', 'url', 'content', 'meta_tags', 'meta_description', 'is_active'] as $field) 
      @include('entries.fields.' . $field) 
     @endforeach 
    @show 


    <div class="form-group"> 
     <div class="col-sm-offset-3 col-sm-6"> 
      @section('submit') 
       {!! Form::submit('Добавить', ['class' => 'btn btn-default']) !!} 
      @show 
     </div> 
    </div> 

    {!! Form::close() !!} 
</div> 
@endsection 

子模板:對父模板

@extends('entries.create') 

@section('title') 
    Добавить статью/{{ config('site.site_name') }} 
@endsection 

@section('fields') 
    @foreach ([ 
    'entries.fields.title', 
    'entries.fields.url', 
     'articles.fields.description', 
     'entries.fields.content', 
     'entries.fields.meta_description', 
     'entries.fields.is_active', 
     'articles.fields.enable_comments', 
     'articles.fields.show_on_main', 
     'articles.fields.rank', 
     ] as $field) 
     @include($field) 
    @endforeach 
@endsection 

模型結合的作品,但在子模板不起作用。

例如,我有enable_comments複選框:

{!! Form::label('enable_comments', 'Включить комментарии', ['class' => 'col-sm-3 control-label']) !!} 

    <div class="col-sm-6"> 
     {!! Form::checkbox('enable_comments', null, null, ['class' => 'checkbox']) !!} 
    </div> 
</div> 

而且它總是選中,而$入門> enable_comments ===真正

我不知道爲什麼會這樣做。也許任何人都可以通過代碼並找到問題。

在此先感謝您的幫助。

回答

0

問題是表單模型綁定僅在當前模板(包含文件)內工作,但不填充子模板中的值。所以唯一的解決方法是在子模板

中再次寫入表單開始({!! Form :: model(...)