当我单击“编辑”按钮时,它将显示一个弹出框,当我编辑该字段并单击“更新”时,它将显示以下错误。
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message
<div id="myEditModal" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myModalLabelEdit" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabelEdit">Edit Department</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<form class="form-horizontal" method="POST" action="{{ route('edit_department', $departmentList->id) }}">
@csrf
<div class="form-group">
<div class="col-md-12">
<input type="text" name="nameOfDepartment" class="form-control" placeholder="Edit Department" value="{{$departmentList->nameOfDepartment}}">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-info waves-effect" data-dismiss="modal">Update</button>
<button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
这是我编辑刀片文件的代码,以下代码在我的web.php文件中
Route::get('add-department', 'DepartmentController@createDepartment')->name('create_department');
Route::post('store-department', 'DepartmentController@storeDepartment')->name('store_department');
Route::get('list-department', 'DepartmentController@listDepartment')->name('list_department');
Route::get('edit-department/{id}', 'DepartmentController@editDepartment')->name('edit_department');
Route::post('update-department/{id}', 'DepartmentController@updateDepartment')->name('update_department');
Route::get('delete-department/{id}', 'DepartmentController@deleteDepartment')->name('delete_department');
答案 0 :(得分:0)
您已经在编辑记录,现在需要在数据库中对其进行更新。因此,您的路线应为更新:
首先,将更新路径更正为:(从发布到发布)
Route::put('update-department/{id}', 'DepartmentController@updateDepartment')->name('update_department');
然后相应地更新您的表单:
<form class="form-horizontal" method="POST" action="{{ route('update_department', $departmentList->id) }}">
@csrf
@method('PUT')
...
出了什么问题:您的表单操作将转到使用GET方法的“编辑”路由,但您使用了POST方法。这就是为什么您获得MethodNotAllowedHttpException
的原因。