PUT请求几天前对我来说工作正常,但现在它们一直返回MethodNotAllowedHttpException。放置请求不起作用,Laravel 4
我按照这个指南:http://scotch.io/tutorials/simple-laravel-crud-with-resource-controllers。
我的创建和索引工作正常,但是当我尝试更新记录时,它给我带来了错误消息。另外,如果我将方法从PUT更改为POST,它将开始添加记录。
形式
{{ Form::open(array('route' => array('timesheet.update', $timesheet->id), 'method' => 'PUT')) }}
{{ Form::label('companyName', 'Company Name') }}
{{ Form::text('companyName', $timesheet['companyName']) }}
{{ Form::label('placement', 'Placement') }}
{{ Form::text('placement', $timesheet['placement']) }}
{{ Form::label('startDate', 'Start Date') }}
{{ Form::text('startDate', $timesheet['startDate']) }}
{{ Form::label('endDate', 'End Date ') }}
{{ Form::text('endDate', $timesheet['endDate']) }}
{{ Form::label('weekending', 'weekending') }}
{{ Form::text('weekending', $timesheet['weekending']) }}
{{ Form::label('status', 'status') }}
{{ Form::text('status', $timesheet['status']) }}
{{ Form::submit('Edit Timesheet') }}
{{ Form::close() }}
控制器
public function update($id)
{
$timesheet = Timesheet::find($id);
$timesheet->companyName = Input::get('companyName');
$timesheet->placement = Input::get('placement');
$timesheet->startDate = Input::get('startDate');
$timesheet->endDate = Input::get('endDate');
$timesheet->weekending = Input::get('weekending');
$timesheet->status = Input::get('status');
$timesheet->save();
return Redirect::to('timesheet');
}
路线
Route::resource('timesheet', 'TimesheetController');
你的功能'更新'可能不得不重新命名为'putUpdate' – JMc 2014-12-01 16:50:52
你的路线真的好吗?你可以用'php artisan routes'来检查你的路线 – 2014-12-01 23:17:21
@JMc它是资源,不是控制器,所以不需要在函数的开头添加'put' – 2014-12-01 23:18:27