I'm trying to send a form to update a certain record in the baco, but it displays the error message:
MethodNotAllowedHttpException
I'm using route resources, my route is defined:
Route::resource('tasks', 'TaskController');
And my form is defined as follows:
<!-- Modal to check a task -->
<div class="modal fade" id="check" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="exampleModalLabel">Atenção!</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="post" action="{{ route('tasks.update',['tasks' => $task->id]) }}">
{{ method_field('put') }}
{{ csrf_field() }}
<p>
Você deseja concluir esta tarefa?
</p>
<input name="code" id="code" type="hidden" value="1">
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Sair</button>
<button type="submit" class="btn btn-success">Concluir</button>
</div>
</form>
</div>
</div>
</div>
</div>
In the Chrome inspect, the modal is being rendered this way:
<div class="modal fade in" id="check" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" style="display: block; padding-right: 17px;">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="exampleModalLabel">Atenção!</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="http://localhost:8000/tasks" method="POST">
<input type="hidden" name="_method" value="PUT"> <input type="hidden" name="_token" value="qhXD31cYFFfSf8pq5xFGtBrVYMAuSLmzq3ExFHt4"> <p>
Você deseja concluir esta tarefa?
</p>
<input name="code" id="code" type="hidden" value="1">
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Sair</button>
<button type="submit" class="btn btn-success">Concluir</button>
</div>
</form>
</div>
</div>
</div>
</div>
In the Network tab, the return of the request is:
- Request URL: http: // localhost: 8000 / tasks
- Request Method: POST
- Status Code: 405 Method Not Allowed
- Remote Address: 127.0.0.1:8000
- Referrer Policy: no-referrer-when-downgrade
- Accept: text / html, application / xhtml + xml, application / xml; q = 0.9, image / webp, image / apng, * / *; q = 0.8
- Accept-Encoding: gzip, deflate, br
- Accept-Language: en-US, at; q = 0.9
- Cache-Control: max-age = 0
- Connection: keep-alive
- Content-Length: 66
- Content-Type: application / x-www-form-urlencoded
- Cookie: XDEBUG_SESSION = PHPSTORM; XSRF-TOKEN = eyJpdiI6IlBBSnFZSm5tZTJseUhxZDlIdVRrMGc9PSIsInZhbHVlIjoidHRvN3RTaStzcEFjck1veDJWa2k0cVwvdkxsalRcL01hYmpIOFhIS2xkeXFUczU1RTFzOTJqMGRZMGJSSGJaNlZ6IiwibWFjIjoiZjBkOGE0NzJjNDQ3OTI0ZmFjYWU0MDA3MmMxNTliMzcxODYxODM1NWFlNGVjOWU1NWEwMzM0ZmQxMDExZTkxYyJ9;
- 3D laravel_session = eyJpdiI6IjVCRnYrcENYRTlieEFtN3BvbFpjOVE9PSIsInZhbHVlIjoiN21wXC81Vk4yZGUwN3FmR1Vzc1k0bjk4R2tkUUs4V3ZiWndYRUVSTFZJdkVlY3VFM0xlVUluRVo3c0xTTWk0M0oiLCJtYWMiOiI3OGMxMjUzZmJmODgxNjg0NDA0ODA0ZDM3Nzk3MWIwMWE0MjFjOGIwMzk0ZmE0OWJkY2MwMmRhNjZlZTY0MGJhIn0%
- Host: localhost: 8000
- Origin: http: // localhost: 8000
- Referer: http: // localhost: 8000 / projects / 1
- Upgrade-Insecure-Requests: 1
- User-Agent: Mozilla / 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit / 537.36 (KHTML, like Gecko) Chrome / 70.0.3538.110 Safari / 537.36
- _method: PUT
- _token: qhXD31cYFFfSf8pq5xFGtBrVYMAuSLmzq3ExFHt4
- code: 1