Back

Form model binding isn't working with section/include


Audiophile posted 2 months ago

Laravel 5.4, laravelcollective/html 5.4.8

Parent Blade template for creating/editing Entries:

(as you see, it includes specific form fields)

@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 for creating Articles (with it's own fields set):

@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 problem is that when I don't redefine 'fields' setcion, the fields have values which the given $entry object contains, but once I've redefined it, the values autofilling stops working.

For example, I have enable_comments checkbox:

<div class="form-group">
    {!!   Form::label('is_active', 'Активна', ['class' => 'col-sm-3 control-label']) !!}

    <div class="col-sm-6">
        {!! Form::checkbox('is_active', 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. How to resolve this problem?

Thanks


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us