这是我的表格:
{{ Form::model($data, array(
'route' => array('waitingtimes.update', $data->id),
'class' => 'mainInformationContrainer',
'method' => 'put'
)) }}
当我提交表格时,我得到了
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
虽然我已将请求设置为put
。
你能帮我吗?
我注意到表单html是
<form method="POST" action="http://localhost:8082/test/public/waitingtimes/2" accept-charset="UTF-8" class="mainInformationContrainer">
</form>
未张贴,
问题是因为我将route
输错了rout
,但我没有收到此异常
Trying to get property of non-object
这是观点:
{{Form::model($data, array(
'route' => array('waitingtimes.update', $data->id)
, 'class' => 'mainInformationContrainer',
'method' => 'put'
))}}
<ul>
<li>
<label>First Time:</label>
<div class="oneInfo">
{{ Form::text('startTime', $value=null, array('class' => 'time ui-timepicker-input', 'id' => 'startTime', 'autocomplete' => 'off'))}}
<span class="errorMessage">
<?php
echo $errors->first('startTime');
?>
</span>
</div>
</li>
<li>
<label>End Time:</label>
<div class="oneInfo">
{{Form::text('endTime', $value=null, array('class' => 'time ui-timepicker-input', 'id' => 'endTime'))}}
<span class="errorMessage">
<?php
echo $errors->first('endTime');
?>
</span>
</div>
</li>
<li>
<label>Value:</label>
<div class="oneInfo">
{{Form::text('value', $value=null, array())}}
<span class="errorMessage">
<?php
echo $errors->first('value');
?>
</span>
</div>
</li>
<li>
<input type="submit" value="Save Changes"/>
<input type="button" value="Cancle" class="cancelButton"/>
</li>
</ul>
{{ Form::close() }}
这是控制器update
$input = Input::all();
$validation = Validator::make($input, WaitingTimes::$rules);
if ($validation->passes()){}else{
return Redirect::route('waitingtimes.edit')->withInput()->withErrors($validation)->with(array(
'verticalMenu'=>'none',
'verticalMenuTab' => 'none',
'data' => $input
));
}
请注意,此html刀片代码用于编辑数据,当我调用编辑功能时它正常工作,当用户尝试编辑信息时,我也使用它来重定向但验证失败
答案 0 :(得分:2)
您需要在表单创建中指定方法,将其添加到Form :: model数组中:
'method' => 'PUT'
答案 1 :(得分:1)
您需要告诉您的表单您将使用方法PUT
:
{{ Form::model($data, array(
'route' => array('waitingtimes.update', $data->id),
'class' => 'mainInformationContrainer',
'method' => 'put',
)) }}
请注意,您仍会在表单中看到method = "POST"
,但Laravel会在您的表单中添加一个名为_method
的隐藏字段。见http://laravel.com/docs/html#opening-a-form
答案 2 :(得分:1)
我找到了解决方案,
是
return Redirect::back()->withInput()->withErrors($validation)->with(array(
'verticalMenu'=>'none',
'verticalMenuTab' => 'none',
'data' => $input
));
感谢这个问题 Laravel form model binding