我的路线遇到了麻烦。 我有以下语法: 控制器:
public function editFee($id)
{
$fee=fees::findorfail($id);
return view('fees.edit',compact('fee'));
}
public function update($id)
{
$fee=fees::findorfail($id);
// return $grade;
// return Request::all();
$fee->update(Request::all());
flash()->success('Successfully Updated!');
return redirect('view');
}
查看:
<div class="col-sm-12">
<div class="row">
<div class="col-lg-6">
<form role="form" method="post" action= 'update'>
{{ method_field('PUT') }}
{{ csrf_field() }}
<div class="form-group">
<label>Fee Type</label>
<input class="form-control" name="fee_type" placeholder="Enter Fee Type Here" value={{"$fee->fee_type"}} required="">
</div>
<div class="form-group">
<label>Amount</label>
<input class="form-control" name="amount" placeholder="Provide Fee Amount" value={{"$fee->amount"}} required="">
</div>
<button type="submit" class="btn btn-default">Update Fee</button>
<button type="reset" class="btn btn-default">Reset</button>
</form>
</div>
</div>
</div>
路线:
Route::get('fees','FeesController@index');
Route::get('fees/add', 'FeesController@addFee');
Route::post('fees/store','FeesController@store');
Route::get('fees/view','FeesController@viewFee');
Route::get('fee/view/{id}/edit','FeesController@editFee');
Route::post('fee/view/{id}/update','FeesController@update');
Route::get('fee/update','FeesController@updateFees');
Route::get('fee/delete','FeesController@deleteFee');
Route::resource('fee','FeesController');
这里有什么问题。当我尝试从@editFee转到@update时,它会出现填充错误:
MethodNotAllowedHttpException
有人可以帮我吗?我被卡住了!
答案 0 :(得分:0)
<form role="form" method="post" action='fee/view/{$fee->id}/update'>
而不是
<form role="form" method="post" action='update'>
原因是表单必须发布到fee/view/{$fee->id}/update
才能到达您想要的控制器。