Laravel:表单数据绑定

时间:2016-01-04 08:26:17

标签: php forms data-binding laravel-5

我需要使用表单数据绑定将数据绑定到相关字段,但数据根本没有显示在字段上。我不知道究竟是什么问题导致数据无法显示。

控制器:

>>> from sklearn import svm
>>> X = [[0, 0], [2, 2]]
>>> y = [0.5, 2.5]
>>> clf = svm.SVR()
>>> clf.fit(X, y) 
SVR(C=1.0, cache_size=200, coef0=0.0, degree=3, epsilon=0.1, gamma='auto',
    kernel='rbf', max_iter=-1, shrinking=True, tol=0.001, verbose=False)
>>> clf.predict([[1, 1]])
array([ 1.5])

查看:

public function edit($id){
$datum = RatingDatum::findorfail(1);
 return view('rating.index',compact('datum'));
}

DD($基准);

<div class="plan bg-plan">
   {!! Form::model($datums,['method' => 'PATCH','action'=>'RatingDataController@update'],$datums->id]) !!}  
   <div class="radio">
           <label>
             {!! Form::radio('customize_question_id')!!}{{$datums->value}}
            </label>
   </div>

   <div class="form-group">
       {!! Form::label('comment','Comment :') !!}
       {!! Form::textarea('comment' ,null,['class'=>'form-control', 'rows' => 4]) !!}

       {!! Form::label('reference','Reference:') !!}
       {!! Form::textarea('reference',null,['class'=>'form-control', 'rows' => 1]) !!}
   </div>
       {!! Form::submit('Submit Data', ['class' => 'btn btn-success submit']) !!}
       {!! Form::close() !!}
   </div>

1 个答案:

答案 0 :(得分:0)

数据未显示在表单中是因为您引用了错误的变量。

您正在传递$datum,并且在视图表单中,您正在访问$datums。这就是你的表单为空的原因。

<强>解决方案:

执行以下任一操作:

  • 将控制器方法&{39}更新为$datum

OR

  • 将表单模型$datums更新为$datums

希望这会帮助你。快乐的编码。欢呼声。