0
I am trying to send a form to update certain record in Baco, but it displays the error message:
Methodnotallowedhttpexception
I am using route Resources, my route is difinida:
Route::resource('tasks', 'TaskController');
And my form is set 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 Chrome’s 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,en;q=0.9
- Cache-Control: max-age=0
- Connection: Keep-Alive
- Content-Length
- Content-Type: application/x-www-form-urlencoded
- Cookie: XDEBUG_SESSION=PHPSTORM; XSRF-TOKEN=;
- 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: qhXD31cYFfSf8pq5xFGtBrVYMAuSLmzq3ExFHt4
- code: 1
You can include in your question how the rendered html of this view looks?
– gmsantos
you would like to see the error screen that was rendered or the rest of my html?
– Gustavo_Tavares
the generated html before giving Submit
– gmsantos
@gmsantos entered as requested. However, the code is inside a file where I am placing all the modal’s of the application.
– Gustavo_Tavares
Try switching to {{ method_field('PATCH') }}
– cau
@caused this change and also remained the error.
– Gustavo_Tavares