doutao1171
2017-05-23 14:33
浏览 78
已采纳

提交POST表单laravel错误

I am using laravel 5.4 and trying to get a form to submit however it doesnt seem to want to work.

So i am getting the error of:

MethodNotAllowedHttpException in RouteCollection.php line 251:
in RouteCollection.php line 251
at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 238
at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 176
at RouteCollection->match(object(Request)) in Router.php line 533
at Router->findRoute(object(Request)) in Router.php line 512

However my form looks like this:

<form action="/cUsers/add/" method="post" id="formSubmit">
        {{csrf_field()}}
        <input id="nameInput" type="text" name="nameInput"
                placeholder="Enter your name"
                class="form-control"
                style="cursor: auto;">
    <input id="emailInput" type="text" name="emailInput"
            placeholder="Enter your email"
            class="form-control">
    <input type="submit">
</form>

And my routes folder looks like this:

Route::group(['domain' => '{company}.test.co.uk'], function () {
    Route::get('/companyVerify/{verifyCode}', 'CompanyController@verifyCompany');
    Route::get('/', 'CompanyController@dashboard');
    Route::get('/cUsers', 'CompanyController@users');
    Route::post('/cUsers/add/', 'CompanyController@addUserToCompany');
});
Route::group(['prefix' => 'admin'], function () {
    Route::group(['prefix' => 'companies'], function () {
        Route::get('/', 'AdminControls@companies');
        Route::get('/create', 'AdminControls@createCompanies');
        Route::post('/create/save', 'AdminControls@saveNewCompany');
    });
});

My routes according to artisan:

+------------------------------+----------+-----------------------------------------+------------------+----------------------------------------------------------------------------+--------------+
| Domain                       | Method   | URI                                     | Name             | Action                                                                     | Middleware   |
+------------------------------+----------+-----------------------------------------+------------------+----------------------------------------------------------------------------+--------------+
|                              | GET|HEAD | /                                       |                  | Closure                                                                    | web          |
| {company}.simpleissues.co.uk | GET|HEAD | /                                       |                  | App\Http\Controllers\CompanyController@dashboard                           | web,auth     |
|                              | GET|HEAD | admin/companies                         |                  | App\Http\Controllers\AdminControls@companies                               | web,auth     |
|                              | GET|HEAD | admin/companies/create                  |                  | App\Http\Controllers\AdminControls@createCompanies                         | web,auth     |
|                              | POST     | admin/companies/create/save             |                  | App\Http\Controllers\AdminControls@saveNewCompany                          | web,auth     |
|                              | GET|HEAD | api/user                                |                  | Closure                                                                    | api,auth:api |
| {company}.simpleissues.co.uk | GET|HEAD | cUsers                                  |                  | App\Http\Controllers\CompanyController@users                               | web,auth     |
| {company}.simpleissues.co.uk | POST     | cUsers/add                              |                  | App\Http\Controllers\CompanyController@addUserToCompany                    | web,auth     |
| {company}.simpleissues.co.uk | GET|HEAD | companyVerify/{verifyCode}              |                  | App\Http\Controllers\CompanyController@verifyCompany                       | web,auth     |
|                              | GET|HEAD | home                                    |                  | App\Http\Controllers\HomeController@index                                  | web,auth     |
|                              | 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          |
|                              | POST     | oauth/authorize                         |                  | \Laravel\Passport\Http\Controllers\ApproveAuthorizationController@approve  | web,auth     |
|                              | GET|HEAD | oauth/authorize                         |                  | \Laravel\Passport\Http\Controllers\AuthorizationController@authorize       | web,auth     |
|                              | DELETE   | oauth/authorize                         |                  | \Laravel\Passport\Http\Controllers\DenyAuthorizationController@deny        | web,auth     |
|                              | POST     | oauth/clients                           |                  | \Laravel\Passport\Http\Controllers\ClientController@store                  | web,auth     |
|                              | GET|HEAD | oauth/clients                           |                  | \Laravel\Passport\Http\Controllers\ClientController@forUser                | web,auth     |
|                              | DELETE   | oauth/clients/{client_id}               |                  | \Laravel\Passport\Http\Controllers\ClientController@destroy                | web,auth     |
|                              | PUT      | oauth/clients/{client_id}               |                  | \Laravel\Passport\Http\Controllers\ClientController@update                 | web,auth     |
|                              | GET|HEAD | oauth/personal-access-tokens            |                  | \Laravel\Passport\Http\Controllers\PersonalAccessTokenController@forUser   | web,auth     |
|                              | POST     | oauth/personal-access-tokens            |                  | \Laravel\Passport\Http\Controllers\PersonalAccessTokenController@store     | web,auth     |
|                              | DELETE   | oauth/personal-access-tokens/{token_id} |                  | \Laravel\Passport\Http\Controllers\PersonalAccessTokenController@destroy   | web,auth     |
|                              | GET|HEAD | oauth/scopes                            |                  | \Laravel\Passport\Http\Controllers\ScopeController@all                     | web,auth     |
|                              | POST     | oauth/token                             |                  | \Laravel\Passport\Http\Controllers\AccessTokenController@issueToken        | throttle     |
|                              | POST     | oauth/token/refresh                     |                  | \Laravel\Passport\Http\Controllers\TransientTokenController@refresh        | web,auth     |
|                              | GET|HEAD | oauth/tokens                            |                  | \Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController@forUser | web,auth     |
|                              | DELETE   | oauth/tokens/{token_id}                 |                  | \Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController@destroy | web,auth     |
|                              | POST     | password/email                          | password.email   | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail      | web,guest    |
|                              | GET|HEAD | password/reset                          | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm     | web,guest    |
|                              | POST     | password/reset                          |                  | App\Http\Controllers\Auth\ResetPasswordController@reset                    | web,guest    |
|                              | GET|HEAD | password/reset/{token}                  | password.reset   | App\Http\Controllers\Auth\ResetPasswordController@showResetForm            | web,guest    |
|                              | GET|HEAD | refreshACL                              |                  | Closure                                                                    | web          |
|                              | GET|HEAD | register                                | register         | App\Http\Controllers\Auth\RegisterController@showRegistrationForm          | web,guest    |
|                              | POST     | register                                |                  | App\Http\Controllers\Auth\RegisterController@register                      | web,guest    |
+------------------------------+----------+-----------------------------------------+------------------+----------------------------------------------------------------------------+--------------+

I dont understand why post isnt working. I have set the route to be post and form as post as well as using the csrf_field(). Could someone explain to my why this isnt working. Thanks

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtmbc1606 2017-05-23 14:59
    已采纳

    Remove the trailing slash from the form action. Laravel is stripping it which can be seen in the route:list

    打赏 评论

相关推荐 更多相似问题