【问题标题】:How can I Solve error while updating the record?更新记录时如何解决错误?
【发布时间】:2019-08-27 01:20:05
【问题描述】:

当我点击编辑按钮时,它会显示一个弹出框,当我编辑字段并点击更新时,它会显示以下错误。

 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');

【问题讨论】:

标签: laravel mongodb eloquent crud


【解决方案1】:

您已经在编辑您的记录,现在您需要在数据库中更新它。所以你的路线应该是更新

首先,将您的更新路线更正为:(从发布到发布)

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 方法的 Edit 路由,但您使用了 POST 方法。这就是你得到MethodNotAllowedHttpException的原因。

【讨论】:

  • 还是一样的错误!
  • @John_rees 我更新了答案,还有问题吗?
猜你喜欢
  • 1970-01-01
  • 2022-10-21
  • 2023-02-20
  • 2021-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-21
相关资源
最近更新 更多