【问题标题】:Form model data not running correctly on @yield Laravel 5表单模型数据在@yield Laravel 5 上未正确运行
【发布时间】:2016-04-04 00:43:11
【问题描述】:

我想要的只是在模板上定义表单模型,然后将产量作为表单数据的内容。但它无法将模型数据正确分配到已定义的每个字段中。 这是我的代码:

template.detail.blade.php

@extends('admin.template.lte.layout.basic')

@section('content-page')
    {!! Form::model($model, ['url' => $formAction]) !!}
        @yield('data-form')
    {!! Form::close() !!}
    @if ($errors->any())
@stop

partial.edit.blade.php

@extends('template.detail')
@section('data-form')
    <div class="form-group">
        {!! Form::label('Dal_Name', 'Alternative Name', ['class' => 'required']) !!}
        {!! Form::text('Dal_Name', null, ['required', 'class' => 'form-control', 'placeholder' => 'Enter Alternative Name']) !!}
    </div>

    <div class="form-group">
        {!! Form::label('Dal_DssID', 'DSS Period', ['class' => 'required']) !!}
        {!! Form::select('Dal_DssID', $dssOptions, null, ['class' => 'form-control']) !!}
    </div>

    <div class="checkbox">
        <label for="Dal_Active">
            {!! Form::hidden('Dal_Active', 'N') !!}
            {!! Form::checkbox('Dal_Active', 'Y') !!}
            Active
        </label>
    </div>
@stop 

我的控制器部分:

     /**
     * Show the form for editing the specified resource.
     *
     * @param  int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $this->data['model'] = DssAlternative::find($id);
        $this->data['formAction'] = \Request::current();
        $this->data['dssOptions'] = Dss::lists('Dss_Name', 'Dss_ID');
        return view('partial.edit', $this->data);
    }

但是模型数据没有传播到正确的形式。 对不起我的英语不好。

【问题讨论】:

    标签: php laravel-5.1 blade laravel-form


    【解决方案1】:

    因为您将$model 对象传递给partial/edit.blade.php 文件,并希望在template/detail.blade.php 中使用它,所以它不起作用

    正好在这一行 {!! Form::model($model, ['url' =&gt; $formAction]) !!}

    解决方案:template/detail.blade.php里面取form模型线是这样的:

    @extends('admin.template.lte.layout.basic')
    
    @section('content-page')
        @yield('data-form')
        @if ($errors->any())
    @stop
    

    所以partial/edit.blade.php 如下所示:

    @extends('template.detail')
    @section('data-form')
    {!! Form::model($model, ['url' => $formAction]) !!}        
        <div class="form-group">
            {!! Form::label('Dal_Name', 'Alternative Name', ['class' => 'required']) !!}
            {!! Form::text('Dal_Name', null, ['required', 'class' => 'form-control', 'placeholder' => 'Enter Alternative Name']) !!}
        </div>
    
        <div class="form-group">
            {!! Form::label('Dal_DssID', 'DSS Period', ['class' => 'required']) !!}
            {!! Form::select('Dal_DssID', $dssOptions, null, ['class' => 'form-control']) !!}
        </div>
    
        <div class="checkbox">
            <label for="Dal_Active">
                {!! Form::hidden('Dal_Active', 'N') !!}
                {!! Form::checkbox('Dal_Active', 'Y') !!}
                Active
            </label>
        </div>
    {!! Form::close() !!}
    @stop 
    

    【讨论】:

    • 感谢 mohammed,我之前尝试过,但我想概括(插入、更新)数据的所有表单打开和关闭结构。但没有机会.. :(
    • 在这种情况下,只需为表单标题添加另一个@yield :)
    猜你喜欢
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    相关资源
    最近更新 更多