将两个模型值传递到laravel 5.1中的一个视图下的不同form.blade进行编辑

时间:2016-08-29 07:50:31

标签: php laravel blade

在我的edit.blade页面中,我已经包含了两个表单刀片,如下所示。要更新我必须为这些刀片传递两个不同的模型数据,但它不能按我的方式工作。请帮帮我。

这是我的编辑刀片:

{!! Form::model($requisitions, array('route' => ['requisition.update', Crypt::encrypt($requisitions->id)], 'id' => 'requisition_update', 'class' => 'form-horizontal row-border')) !!}
                @include('department_user.requisitions._form')
                 <div style="height:30px;"></div>
                    <h4> Requisition Material(s) </h4>
                    @include('department_user.requisitions._item_form')
                <div class="col-md-12"> 
                    {!! Form::label('', '', array('class' => 'col-md-2 control-label')) !!}
                    {!! Form:: submit('Update', ['class' => 'btn btn-success']) !!}
                </div>
            {!!form::close()!!}

我的功能是

public function edit( $id ) {
        $id = Crypt::decrypt($id);
        $requisitions = Requisition::findOrFail($id);
        $requisitionitems = RequisitionItem::findOrFail($id);
        $chargeable_accounts    = [''=> 'Select Chargeable Account'] + ChargeableAccount::whereStatus(1)->orderBy('name', 'DESC')->lists('name', 'id')->toArray();

        $item_measurements    = [''=> 'Select Item'] + ItemMeasurement::whereStatus(1)->orderBy('item_name', 'DESC')->lists('item_name', 'id')->toArray();

        $units    = ['' => 'Select Unit'] + MeasurementUnit::whereStatus(1)->orderBy('name', 'DESC')->lists('name', 'id')->toArray();
        return view('department_user.requisitions.edit', compact('units', 'item_measurements', 'chargeable_accounts', 'requisitions','requisitionitems'));
    }

1 个答案:

答案 0 :(得分:0)

要将数据传递给include,只需使用第二个参数

@include('department_user.requisitions._item_form', $modelA)
@include('department_user.requisitions._item_form', $modelB)

这应该可以解决问题。也:

{!!form::close()!!}

{!!Form::close()!!}