Symfony \组件\ HttpKernel \异常\ MethodNotAllowedHttpException-Laravel 5.7

时间:2019-02-07 15:11:32

标签: php laravel laravel-5 laravel-5.7 html-form-post

我有一条路线

Route::post('skill/store','SkillController@store');

我有一个称呼它的表格

{!! Form::open(array('class' => 'form-horizontal', 'role' =>'form', 'url'=>'skill/store','files' => true, 'method' => 'POST' )) !!}

提交时,我一直得到

  

Symfony \组件\ HttpKernel \ Exception \ MethodNotAllowedHttpException

如何进一步调试呢?

+--------+----------+--------------------------------------------------------+-----------------------------+------------------------------------------------------------------------+----------------+
| Domain | Method   | URI                                                    | Name                        | Action                                                                 | Middleware     |
+--------+----------+--------------------------------------------------------+-----------------------------+------------------------------------------------------------------------+----------------+
|        | POST     | /                                                      |                             | App\Http\Controllers\AccountController@postSignIn                      | web            |
|        | GET|HEAD | /                                                      |                             | App\Http\Controllers\FEController@index                                | web            |
|        | GET|HEAD | api/distributors                                       |                             | App\Http\Controllers\APIController@getDistributors                     | web            |
|        | GET|HEAD | api/reset-password                                     |                             | App\Http\Controllers\APIController@resetPassword                       | web            |
|        | GET|HEAD | code/{file}/_                                          |                             | App\Http\Controllers\ToolController@showFile                           | web            |
|        | GET|HEAD | coding-puzzle                                          |                             | App\Http\Controllers\CodeController@codingPuzzle                       | web            |
|        | POST     | coding-puzzle/process                                  |                             | App\Http\Controllers\CodeController@codingPuzzleProcess                | web            |
|        | GET|HEAD | contact                                                |                             | App\Http\Controllers\ContactController@index                           | web,auth       |
|        | POST     | contact-form                                           |                             | App\Http\Controllers\AccountController@contact                         | web            |
|        | GET|HEAD | contact/{id}                                           |                             | App\Http\Controllers\ContactController@show                            | web,auth       |
|        | DELETE   | contact/{id}/destroy                                   | contact.destroy             | App\Http\Controllers\ContactController@destroy                         | web,auth       |
|        | GET|HEAD | dashboard                                              |                             | App\Http\Controllers\FEController@dashboard                            | web,auth       |
|        | POST     | forgot-password                                        | forgot-password-post        | App\Http\Controllers\AccountController@postForgotPassword              | web            |
|        | GET|HEAD | getCaptivePortalURLs/{hostname}/{cpe_mac}/{device_mac} |                             | App\Http\Controllers\ToolController@getCaptivePortalURLs               | web            |
|        | GET|HEAD | getCertbyHostName/{hostname}                           |                             | App\Http\Controllers\ToolController@getCertbyHostName                  | web            |
|        | GET|HEAD | getCommitIDBaseOnBuildNumber/{buildNumber}             |                             | App\Http\Controllers\ToolController@getCommitIDBaseOnBuildNumber       | web            |
|        | GET|HEAD | getImagesFromSite/{hostname}                           |                             | App\Http\Controllers\ToolController@getImagesFromSite                  | web            |
|        | GET|HEAD | getUpdateServiceTypeCommand                            |                             | App\Http\Controllers\ToolController@getUpdateServiceTypeCommand        | web            |
|        | GET|HEAD | getskilldata                                           | getskilldata                | App\Http\Controllers\SkillController@skilldata                         | web            |
|        | GET|HEAD | guest                                                  |                             | App\Http\Controllers\GuestController@index                             | web,auth       |
|        | GET|HEAD | guest/create                                           | guest.create                | App\Http\Controllers\GuestController@create                            | web,auth       |
|        | POST     | guest/store                                            |                             | App\Http\Controllers\GuestController@store                             | web,auth       |
|        | GET|HEAD | guest/{id}                                             |                             | App\Http\Controllers\GuestController@show                              | web,auth       |
|        | DELETE   | guest/{id}/destroy                                     | guest.destroy               | App\Http\Controllers\GuestController@destroy                           | web,auth       |
|        | GET|HEAD | guest/{id}/edit                                        |                             | App\Http\Controllers\GuestController@edit                              | web,auth       |
|        | PUT      | guest/{id}/update                                      | guest.update                | App\Http\Controllers\GuestController@update                            | web,auth       |
|        | GET|HEAD | image                                                  |                             | App\Http\Controllers\ImageController@index                             | web,auth,admin |
|        | GET|HEAD | image/create                                           |                             | App\Http\Controllers\ImageController@create                            | web,auth,admin |
|        | POST     | image/store                                            |                             | App\Http\Controllers\ImageController@store                             | web,auth,admin |
|        | PUT      | image/type/{id}/update                                 |                             | App\Http\Controllers\ImageController@updateType                        | web,auth,admin |
|        | GET|HEAD | image/types                                            |                             | App\Http\Controllers\ImageController@types                             | web,auth,admin |
|        | GET|HEAD | image/{id}                                             |                             | App\Http\Controllers\ImageController@get                               | web,auth,admin |
|        | DELETE   | image/{id}/destroy                                     |                             | App\Http\Controllers\ImageController@destroy                           | web,auth,admin |
|        | GET|HEAD | image/{id}/edit                                        |                             | App\Http\Controllers\ImageController@edit                              | web,auth,admin |
|        | PUT      | image/{id}/update                                      |                             | App\Http\Controllers\ImageController@update                            | web,auth,admin |
|        | GET|HEAD | images                                                 |                             | App\Http\Controllers\ImageController@all                               | web,auth,admin |
|        | GET|HEAD | info                                                   |                             | App\Http\Controllers\FEController@info                                 | web            |
|        | POST     | login                                                  |                             | App\Http\Controllers\Auth\LoginController@login                        | web,guest      |
|        | GET|HEAD | login                                                  | login                       | App\Http\Controllers\Auth\LoginController@showLoginForm                | web,guest      |
|        | POST     | logout                                                 | logout                      | App\Http\Controllers\Auth\LoginController@logout                       | web            |
|        | GET|HEAD | logout                                                 |                             | App\Http\Controllers\FEController@getSignout                           | web,auth       |
|        | GET|HEAD | logs                                                   |                             | App\Http\Controllers\GeneralController@logs                            | web,auth,admin |
|        | GET|HEAD | nuc/{tableName}                                        |                             | App\Http\Controllers\DatabaseController@show                           | web            |
|        | POST     | password/email                                         | password.email              | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest      |
|        | POST     | password/reset                                         | password.update             | App\Http\Controllers\Auth\ResetPasswordController@reset                | web,guest      |
|        | GET|HEAD | password/reset                                         | password.request            | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest      |
|        | GET|HEAD | password/reset/{token}                                 | password.reset              | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest      |
|        | GET|HEAD | phpinfo                                                |                             | App\Http\Controllers\GeneralController@phpinfo                         | web,auth       |
|        | GET|HEAD | portfolio                                              |                             | App\Http\Controllers\PortfolioController@index                         | web,auth,admin |
|        | GET|HEAD | portfolio/all                                          |                             | App\Http\Controllers\FEController@portfolioall                         | web            |
|        | GET|HEAD | portfolio/create                                       |                             | App\Http\Controllers\PortfolioController@create                        | web,auth,admin |
|        | POST     | portfolio/image/{id}/destroy                           |                             | App\Http\Controllers\PortfolioController@destroyImage                  | web,auth,admin |
|        | POST     | portfolio/store                                        |                             | App\Http\Controllers\PortfolioController@store                         | web,auth,admin |
|        | DELETE   | portfolio/{id}/destroy                                 |                             | App\Http\Controllers\PortfolioController@destroy                       | web,auth,admin |
|        | GET|HEAD | portfolio/{id}/edit                                    |                             | App\Http\Controllers\PortfolioController@edit                          | web,auth,admin |
|        | GET|HEAD | portfolio/{id}/get                                     |                             | App\Http\Controllers\PortfolioController@get                           | web,auth,admin |
|        | POST     | portfolio/{id}/update                                  |                             | App\Http\Controllers\PortfolioController@update                        | web,auth,admin |
|        | GET|HEAD | projects/oop/{id}                                      |                             | App\Http\Controllers\ProjectController@oop                             | web,auth,admin |
|        | GET|HEAD | register                                               | register                    | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest      |
|        | POST     | register                                               |                             | App\Http\Controllers\AccountController@postRegister                    | web            |
|        | POST     | reset-password                                         | reset-password-post         | App\Http\Controllers\AccountController@postReSetPassword               | web            |
|        | GET|HEAD | reset-password/{code}                                  | reset-password              | App\Http\Controllers\AccountController@getReSetPassword                | web            |
|        | GET|HEAD | resume                                                 |                             | App\Http\Controllers\GeneralController@resume                          | web            |
|        | GET|HEAD | resume/doc                                             |                             | App\Http\Controllers\GeneralController@resumeDoc                       | web            |
|        | GET|HEAD | run/{file}                                             |                             | App\Http\Controllers\GeneralController@code                            | web            |
|        | GET|HEAD | run/{file}/_                                           |                             | App\Http\Controllers\ToolController@showFile                           | web            |
|        | GET|HEAD | seed/{tableName}                                       |                             | App\Http\Controllers\DatabaseController@seed                           | web            |
|        | POST     | set-password                                           | set-password-post           | App\Http\Controllers\AccountController@postSetPassword                 | web            |
|        | GET|HEAD | set-password/{code}                                    | set-password                | App\Http\Controllers\AccountController@getSetPassword                  | web            |
|        | GET|HEAD | showFiles                                              |                             | App\Http\Controllers\ToolController@showFiles                          | web            |
|        | GET|HEAD | showFiles/{fileName}                                   |                             | App\Http\Controllers\ToolController@showFile                           | web            |
|        | GET|HEAD | skill                                                  |                             | App\Http\Controllers\SkillController@index                             | web,auth,admin |
|        | GET|HEAD | skill/create                                           |                             | App\Http\Controllers\SkillController@create                            | web,auth,admin |
|        | POST     | skill/store                                            | skill.store                 | App\Http\Controllers\SkillController@store                             | web,auth,admin |
|        | DELETE   | skill/{id}/destroy                                     |                             | App\Http\Controllers\SkillController@destroy                           | web,auth,admin |
|        | GET|HEAD | skill/{id}/edit                                        |                             | App\Http\Controllers\SkillController@edit                              | web,auth,admin |
|        | POST     | skill/{id}/update                                      |                             | App\Http\Controllers\SkillController@update                            | web,auth,admin |
|        | GET|HEAD | skills                                                 |                             | App\Http\Controllers\SkillController@all                               | web            |
|        | GET|HEAD | user                                                   |                             | App\Http\Controllers\UserController@index                              | web,auth,admin |
|        | GET|HEAD | user-profile/{id}                                      |                             | App\Http\Controllers\UserController@profile                            | web,auth       |
|        | GET|HEAD | user/create                                            | user.create                 | App\Http\Controllers\UserController@create                             | web,auth,admin |
|        | POST     | user/store                                             | user.store                  | App\Http\Controllers\UserController@store                              | web,auth,admin |
|        | GET|HEAD | user/{id}                                              |                             | App\Http\Controllers\UserController@show                               | web,auth,admin |
|        | DELETE   | user/{id}/destroy                                      | user.destroy                | App\Http\Controllers\UserController@destroy                            | web,auth       |
|        | GET|HEAD | user/{id}/edit                                         |                             | App\Http\Controllers\UserController@edit                               | web,auth       |
|        | PUT      | user/{id}/update                                       | user.update                 | App\Http\Controllers\UserController@update                             | web,auth       |
|        | PUT      | user/{id}/update_basic_info                            | user.update_basic_info      | App\Http\Controllers\UserController@update_basic_info                  | web,auth       |
|        | PUT      | user/{id}/update_contact_info                          | user.update_contact_info    | App\Http\Controllers\UserController@update_contact_info                | web,auth       |
|        | PUT      | user/{id}/update_cover_picture                         | user.update_cover_picture   | App\Http\Controllers\UserController@update_cover_picture               | web,auth       |
|        | PUT      | user/{id}/update_profile_picture                       | user.update_profile_picture | App\Http\Controllers\UserController@update_profile_picture             | web,auth       |
|        | PUT      | user/{id}/update_summary_info                          | user.update_summary_info    | App\Http\Controllers\UserController@update_summary_info                | web,auth       |
|        | GET|HEAD | visitor                                                |                             | App\Http\Controllers\VisitorController@index                           | web,auth,admin |
|        | DELETE   | visitor/truncate                                       | visitor.truncate            | App\Http\Controllers\VisitorController@truncate                        | web,auth,admin |
|        | GET|HEAD | visitor/{id}                                           |                             | App\Http\Controllers\VisitorController@show                            | web,auth,admin |
|        | GET|HEAD | wedding                                                |                             | App\Http\Controllers\WeddingController@index                           | web            |
|        | GET|HEAD | wedding/guest/api                                      |                             | App\Http\Controllers\WeddingController@api                             | web            |
|        | GET|HEAD | wedding/guest/{id}/note/display                        |                             | App\Http\Controllers\WeddingController@display                         | web            |
|        | GET|HEAD | wedding/guest/{id}/note/not_display                    |                             | App\Http\Controllers\WeddingController@notDisplay                      | web            |
|        | GET|HEAD | wedding/invite                                         |                             | App\Http\Controllers\WeddingController@invite                          | web            |
|        | GET|HEAD | wedding/mexico                                         |                             | App\Http\Controllers\WeddingController@mexico                          | web            |
|        | POST     | wedding/note                                           |                             | App\Http\Controllers\WeddingController@note                            | web            |
|        | POST     | wedding/rsvp                                           |                             | App\Http\Controllers\WeddingController@rsvp                            | web            |
|        | GET|HEAD | works                                                  |                             | App\Http\Controllers\ImageController@works                             | web            |
+--------+----------+--------------------------------------------------------+-----------------------------+------------------------------------------------------------------------+----------------+

3 个答案:

答案 0 :(得分:3)

在表单的操作中使用诸如skill/store这样的硬编码url总是一个坏主意,尤其是在这种情况下,当您很好地命中相对URL时。

命名您的路线:

Route::post('skill/store','SkillController@store')->name('skill.store');

...并将表单的操作更改为

{!! Form::open(array('class' => 'form-horizontal', 'role' =>'form', 'route'=> 'skill.store' ,'files' => true, 'method' => 'POST' )) !!}

编辑:或者,您也可以如下指定操作属性:

{!! Form::open(array('class' => 'form-horizontal', 'role' =>'form', 'action'=> 'SkillController@store', 'files' => true )) !!}

编辑2 :从您的屏幕快照看来,没有为skill/store定义GET路由。在您的特定情况下,您需要定义通常会显示成功消息的路线,也可以这样做。

public function store(Request $request)
{
    // save the record

    return back()->with('success', 'The record has been saved successfully'); 
}

这将使您返回到先前的路由,该路由存在,并且还可以在视图中添加成功消息。

答案 1 :(得分:1)

当您调用Route :: method类时,它仅接受通过该方法进行调用。因此,根据您的情况,该帖子无法正常工作。首先,我将发布表单,并将其作为请求方法var_dump。

答案 2 :(得分:0)

我有同样的错误。 为了进行调试,我决定检查match方法中的$ Request变量(在我的案例中,第157行在... \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ RouteCollection.php文件中)

public function match(Request $request)
{
    $routes = $this->get($request->getMethod());
    dd($request);

以我为例,我发现该方法不是POST而是PATCH ...

警告:顺便说一句,如果您决定修改框架文件中的任何代码,在进行此类测试之前进行提交或备份,请小心一点。

我希望这会有所帮助。