Reputation: 1753
On a Laravel 8.x application, a PUT request does not work with the the Standard Request
Class.
save() {
let formData = this.prepareFormInput('save');
this.saveBeforeHook();
axios.put(`/${this.model}/edit`, formData, this.axiosHeaders)
.then(r => {
if(r.data.errors) {
this.formDialog.errors = r.data.errors;
} else {
if(r.data.record) {
this.saveAfterHook(r.data.record);
}
this.$root.formDialog.show = false;
this.$root.formMode = "add";
}
}).
catch(e => {
if(e.response.data.errors) {
this.formDialog.errors = e.response.data.errors;
}
});
}
I have validated that the PUT request is sending the correct parameters:
However the request object does not correctly set any posted data. Looing at the request object, none of the data is set.
I have isolated the issue down to a PUT
request in Laravel 8.x
.
Using a POST
request with the same information in Laravel 8.x
works fine.
However the PUT
request does not SET parameters into the Request object:
Using the same PUT request in a Laravel 5.x
application works fine.
Why are PUT requests not properly functioning in Laravel 8.x
?
Upvotes: 2
Views: 234
Reputation: 1858
I think this will fix your problem
For PUT
you want to make your form like
<form action="/example" method="POST">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
or
<form action="/example" method="POST">
@method('PUT')
@csrf
</form>
For more info: Form Method Spoofing
EDIT:
If you are using ajax
then use method
as "POST" and pass _method
value as "PUT". For more info: Laravel AJAX PUT & DELETE
Upvotes: 2