Reputation: 626
In my laravel 5.7 app I make form for updating of data, like:
<section class="card-body">
<h4 class="card-title">Edit vote</h4>
<form method="PUT" action="{{ url('/admin/votes/update/'.$vote->id) }}" accept-charset="UTF-8" id="form_vote_edit" class="form-horizontal"
enctype="multipart/form-data">
{!! csrf_field() !!}
<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
with routes dined in routes/web.php:
Route::group(['middleware' => ['auth', 'isVerified', 'CheckUserStatus'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
...
Route::put('/votes/update/{vote_id}', 'Admin\VotesController@update');
but submitting the form I got request with error:
Request URL: http://local-votes.com/admin/votes/update/22?_token=0CEQg05W4jLWtpF3xB6BGSdz1icwysiDOStLVgHv&id=22&name=gg...
Request Method: GET
Status Code: 405 Method Not Allowed
Why GET request, what is wrong in my form ?
Thanks!
Upvotes: 1
Views: 807
Reputation: 8242
HTML Forms only support GET
and POST
.
From the docs:
Since HTML forms can't make PUT, PATCH, or DELETE requests, you will need to add a hidden _method field to spoof these HTTP verbs.
You can use the method_field helper or the @method blade directive to add the hidden input.
<form action="/foo/bar" method="POST">
@method('PUT')
...
</form>
or
<form action="/foo/bar" method="POST">
{{ method_field('PUT') }}
...
</form>
Upvotes: 5