RouteCollection.php第218:4行中的MethodNotAllowedHttpException [英] MethodNotAllowedHttpException in RouteCollection.php line 218:4
问题描述
在laravel中提交表单时,我将获得MethodNotAllowedHttpException
HTML文件
<form method="POST" action="/cards/{{$card->id}}/notes">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<textarea name="body" class="form-control"></textarea>
<button type="submit">Add Note</button>
</form>
routes.php
Route::post('cards/{card}/notes','NotesController@store');
NotesController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class NotesController extends Controller
{
public function store()
{
return request()->all();
}
}
确保您没有路线,例如说Route::post
,其参数位于您要点击的路线的前面.>
例如:
Route::post('{something}', 'SomethingController@index');
Route::post('cards/{card}/notes', 'NotesController@store');
在这种情况下,无论您尝试发送到卡片路线的什么内容,它都会始终命中something
路线,因为{something}
会截取cards
作为有效参数并触发SomethingController
.
将something
路线放在纸牌路线下方,它应该可以工作.
I will get MethodNotAllowedHttpException when submitting a form in laravel
Html file
<form method="POST" action="/cards/{{$card->id}}/notes">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<textarea name="body" class="form-control"></textarea>
<button type="submit">Add Note</button>
</form>
routes.php
Route::post('cards/{card}/notes','NotesController@store');
NotesController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class NotesController extends Controller
{
public function store()
{
return request()->all();
}
}
Make sure you don't have a route, say a Route::post
with a parameter that lies in front of the route you are trying to hit.
For example:
Route::post('{something}', 'SomethingController@index');
Route::post('cards/{card}/notes', 'NotesController@store');
In this case, no matter what you try to send to the cards route, it will always hit the something
route because {something}
is intercepting cards
as a valid parameter and triggers the SomethingController
.
Put the something
route below the cards route and it should work.
这篇关于RouteCollection.php第218:4行中的MethodNotAllowedHttpException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!