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