Route :: post()显示此错误:MethodNotAllowedHttpException
问题描述:
Route::post()
shows the following error:
MethodNotAllowedHttpException in RouteCollection.php line 219
I changed the route ::post()
into get()
. That's working fine, but I want to use it this way:
Route::post()
Here is my form:
<form role="form" method="post" accept="">
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Here is the route:
Route::post('/posts', 'Cdesignation@index');
How can I solve this error, where is the problem?
答
Do you handle showing the form and its submitting in the same Controller method?
If so, you should have in the Routes both Methods allowed:
Route::get('/posts', 'Cdesignation@index');
Route::post('/posts', 'Cdesignation@index');
答
I don't see any action attribute in your form. Try adding action="/posts" in form attributes.