简体   繁体   中英

Laravel 5.1.26 : MethodNotAllowedHttpException in RouteCollection.php line 219

I will get MethodNotAllowedHttpException when submitting a form in laravel

HTML file

<form action="{{ action('HomeController@store') }}" method="post">
<input name="_method" type="hidden" value="PATCH">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<input type="submit" name="Submit" value="submit">
</form>

Im my routes.php

Route::post('formaction','HomeController@store')

Controller.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class HomeController extends Controller
{
   public function store(){
      echo 'form submitted';
    }
}

Why i will get MethodNotAllowedHttpException in my form action page? I've refereed some questions related to this,but nothing help me

Even if the form is using the POST method, you are sending the extra param _method which will let the framework know that you want to use that method instead. If you send that extra param then you should set the route accordingly:

Route::patch('formaction','HomeController@store');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM