Estou tentando enviar um form para atualizar determinado registro no baco, mas exibe a mensagem de erro:
MethodNotAllowedHttpException
Estou utilizando o route resources, minha rota está difinida:
Route::resource('tasks', 'TaskController');
E meu form está definido da seguinte forma:
<!-- 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>
No inspect do Chrome, está sendo renderizado o modal desta forma:
<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>
Já na aba Network, o retorno da requisiçao é:
- 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,en;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;
- laravel_session=eyJpdiI6IjVCRnYrcENYRTlieEFtN3BvbFpjOVE9PSIsInZhbHVlIjoiN21wXC81Vk4yZGUwN3FmR1Vzc1k0bjk4R2tkUUs4V3ZiWndYRUVSTFZJdkVlY3VFM0xlVUluRVo3c0xTTWk0M0oiLCJtYWMiOiI3OGMxMjUzZmJmODgxNjg0NDA0ODA0ZDM3Nzk3MWIwMWE0MjFjOGIwMzk0ZmE0OWJkY2MwMmRhNjZlZTY0MGJhIn0%3D
- 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