O
O
Outsider V.2017-08-08 16:34:54
Laravel
Outsider V., 2017-08-08 16:34:54

Why doesn't Form Model Binding work when inheriting the Blade template?

Laravel 5.4, laravelcollective/html 5.4.8
There is a basic add content page 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

(as you can see, certain form fields are loaded in it via include)
And there is a template for adding articles that extends it, which has its own set of fields:
@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

The point is that when I do not redefine the contents of the form_fields section, the fields are filled with the values ​​from the $entry variable given to the template, but as soon as I redefine the section, prescribing even the same fields, autocomplete stops working.
For example, I have the 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 in the form of adding articles, it always turns out to be unchecked, although $entry>enable_comments === true
If I do not override the section, then it is set according to the provided model instance - checked.
Why such strange behavior, and how to solve this problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question