Parent blade template:
@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
Child template:
@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
Model binding works for parent template, but doesn't work in child template.
For example, I have enable_comments checkbox:
{!! 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>
And it is always unchecked, while the $entry->enable_comments === true
I don't know why this is happening. Maybe anyone can go through the code and find the problem.
Thanks in advance for your help.
The problem is that form model binding works only inside the current template (with included files), but doesn't fill the values in child temlates. So the only solution is to write form start ( {!! Form::model(... )again, in the child template