Reputation: 1665
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
Upvotes: 1
Views: 2958
Reputation: 24276
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');
Upvotes: 2