Http request 500 internal server error on Axios put
I have an issue submitting my updated data to database.
It accepts all input but when I'm trying to get it saved it gets the error.
This is my route:
Route::resource('Sales', 'SalesController');
How I put my data:
axios.put('/Sales/' + id)
My update method:
public function update(Request $req, $id){
$sales = Sales::find($id);
$sales = new Sales;
$sales->itemQty = $req['itemQty'];
$sales->itemID = $req['itemID'];
$sales->save();
}
My Editing form:
<div class="card-body" v-for="(sale, index) in sales" :key="sale.id">
<form action="/Sales" method="post">
<div>
<input type="hidden" name="_token" :value="csrf">
<div class="form-group">
<div class="form-inline">
<div class="mr-3 mt-2">Item ID: </div>
<input class="form-control mt-2 col" name="itemID" maxlength="12" v-model="sale.itemID">
</div>
<div class="form-inline">
<div class="mr-2 mt-2">Quantity: </div>
<input type="number" min="1" class="form-control mt-2 col" placeholder="Quantity" name="itemQty" v-model="sale.itemQty">
</div>
</div>
</div>
<div class="updatesale" style="margin:0 auto; text-align: center;">
<button class="btn btn-success mt-2" type="button" name="button" v-on:click="updateSalesRec(sale.id)">Update</button>
</div>
</form>
</div>
What is wrong with it?
php laravel vue.js axios
add a comment |
I have an issue submitting my updated data to database.
It accepts all input but when I'm trying to get it saved it gets the error.
This is my route:
Route::resource('Sales', 'SalesController');
How I put my data:
axios.put('/Sales/' + id)
My update method:
public function update(Request $req, $id){
$sales = Sales::find($id);
$sales = new Sales;
$sales->itemQty = $req['itemQty'];
$sales->itemID = $req['itemID'];
$sales->save();
}
My Editing form:
<div class="card-body" v-for="(sale, index) in sales" :key="sale.id">
<form action="/Sales" method="post">
<div>
<input type="hidden" name="_token" :value="csrf">
<div class="form-group">
<div class="form-inline">
<div class="mr-3 mt-2">Item ID: </div>
<input class="form-control mt-2 col" name="itemID" maxlength="12" v-model="sale.itemID">
</div>
<div class="form-inline">
<div class="mr-2 mt-2">Quantity: </div>
<input type="number" min="1" class="form-control mt-2 col" placeholder="Quantity" name="itemQty" v-model="sale.itemQty">
</div>
</div>
</div>
<div class="updatesale" style="margin:0 auto; text-align: center;">
<button class="btn btn-success mt-2" type="button" name="button" v-on:click="updateSalesRec(sale.id)">Update</button>
</div>
</form>
</div>
What is wrong with it?
php laravel vue.js axios
Please show the exact error
– Elisha Senoo
Nov 25 '18 at 17:01
How do I get the exact error?
– ahpenggggg
Nov 25 '18 at 17:40
add a comment |
I have an issue submitting my updated data to database.
It accepts all input but when I'm trying to get it saved it gets the error.
This is my route:
Route::resource('Sales', 'SalesController');
How I put my data:
axios.put('/Sales/' + id)
My update method:
public function update(Request $req, $id){
$sales = Sales::find($id);
$sales = new Sales;
$sales->itemQty = $req['itemQty'];
$sales->itemID = $req['itemID'];
$sales->save();
}
My Editing form:
<div class="card-body" v-for="(sale, index) in sales" :key="sale.id">
<form action="/Sales" method="post">
<div>
<input type="hidden" name="_token" :value="csrf">
<div class="form-group">
<div class="form-inline">
<div class="mr-3 mt-2">Item ID: </div>
<input class="form-control mt-2 col" name="itemID" maxlength="12" v-model="sale.itemID">
</div>
<div class="form-inline">
<div class="mr-2 mt-2">Quantity: </div>
<input type="number" min="1" class="form-control mt-2 col" placeholder="Quantity" name="itemQty" v-model="sale.itemQty">
</div>
</div>
</div>
<div class="updatesale" style="margin:0 auto; text-align: center;">
<button class="btn btn-success mt-2" type="button" name="button" v-on:click="updateSalesRec(sale.id)">Update</button>
</div>
</form>
</div>
What is wrong with it?
php laravel vue.js axios
I have an issue submitting my updated data to database.
It accepts all input but when I'm trying to get it saved it gets the error.
This is my route:
Route::resource('Sales', 'SalesController');
How I put my data:
axios.put('/Sales/' + id)
My update method:
public function update(Request $req, $id){
$sales = Sales::find($id);
$sales = new Sales;
$sales->itemQty = $req['itemQty'];
$sales->itemID = $req['itemID'];
$sales->save();
}
My Editing form:
<div class="card-body" v-for="(sale, index) in sales" :key="sale.id">
<form action="/Sales" method="post">
<div>
<input type="hidden" name="_token" :value="csrf">
<div class="form-group">
<div class="form-inline">
<div class="mr-3 mt-2">Item ID: </div>
<input class="form-control mt-2 col" name="itemID" maxlength="12" v-model="sale.itemID">
</div>
<div class="form-inline">
<div class="mr-2 mt-2">Quantity: </div>
<input type="number" min="1" class="form-control mt-2 col" placeholder="Quantity" name="itemQty" v-model="sale.itemQty">
</div>
</div>
</div>
<div class="updatesale" style="margin:0 auto; text-align: center;">
<button class="btn btn-success mt-2" type="button" name="button" v-on:click="updateSalesRec(sale.id)">Update</button>
</div>
</form>
</div>
What is wrong with it?
php laravel vue.js axios
php laravel vue.js axios
edited Nov 25 '18 at 21:32
Elisha Senoo
1,1742817
1,1742817
asked Nov 25 '18 at 16:21
ahpengggggahpenggggg
61
61
Please show the exact error
– Elisha Senoo
Nov 25 '18 at 17:01
How do I get the exact error?
– ahpenggggg
Nov 25 '18 at 17:40
add a comment |
Please show the exact error
– Elisha Senoo
Nov 25 '18 at 17:01
How do I get the exact error?
– ahpenggggg
Nov 25 '18 at 17:40
Please show the exact error
– Elisha Senoo
Nov 25 '18 at 17:01
Please show the exact error
– Elisha Senoo
Nov 25 '18 at 17:01
How do I get the exact error?
– ahpenggggg
Nov 25 '18 at 17:40
How do I get the exact error?
– ahpenggggg
Nov 25 '18 at 17:40
add a comment |
1 Answer
1
active
oldest
votes
You don't need to create another instance of the Sales
object after finding it:
public function update(Request $req, $id){
$sales = Sales::find($id);
$sales->itemQty = $req['itemQty'];
$sales->itemID = $req['itemID'];
$sales->save();
}
I don't think your intention is to have your data submitted in array. So remove from the input field names:
<div class="card-body" v-for="(sale, index) in sales" :key="sale.id">
<form action="/Sales" method="post">
<div>
<input type="hidden" name="_token" :value="csrf">
<div class="form-group">
<div class="form-inline">
<div class="mr-3 mt-2">Item ID: </div>
<input class="form-control mt-2 col" name="itemID" maxlength="12" v-model="sale.itemID">
</div>
<div class="form-inline">
<div class="mr-2 mt-2">Quantity: </div>
<input type="number" min="1" class="form-control mt-2 col" placeholder="Quantity" name="itemQty" v-model="sale.itemQty">
</div>
</div>
</div>
<div class="updatesale" style="margin:0 auto; text-align: center;">
<button class="btn btn-success mt-2" type="button" name="button" v-on:click="updateSalesRec(sale.id)">Update</button>
</div>
</form>
</div>
Hope this is useful.
Did not make any differences. However I did notice something with my delete function. public function destroy(Request $req, $id) { $sales = Sales::find($id); $sales->delete(); return redirect()->action('pagesController@dSales'); } This works although I do get 500 internal sever error
– ahpenggggg
Nov 25 '18 at 17:43
Found the error. Apparently Im sending null data even with the new input so i get Integrity Violation Error. What do I do with this>
– ahpenggggg
Nov 25 '18 at 17:51
Which field is submitting the null data? You can set the value before it is submitted, or set a default value on database. If you have some constrains on the database field (like unique), then you either remove the constraint or ensure it is always satisfied.
– Elisha Senoo
Nov 25 '18 at 17:55
All fields. The default value of database is fine as I can do initial post request to have my data submitted. This however, my edited data does not get accepted and is submitted as null. How do I make sure upon clearing the existing data from the field, then the newly input data is being set ?
– ahpenggggg
Nov 25 '18 at 18:22
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53469462%2fhttp-request-500-internal-server-error-on-axios-put%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You don't need to create another instance of the Sales
object after finding it:
public function update(Request $req, $id){
$sales = Sales::find($id);
$sales->itemQty = $req['itemQty'];
$sales->itemID = $req['itemID'];
$sales->save();
}
I don't think your intention is to have your data submitted in array. So remove from the input field names:
<div class="card-body" v-for="(sale, index) in sales" :key="sale.id">
<form action="/Sales" method="post">
<div>
<input type="hidden" name="_token" :value="csrf">
<div class="form-group">
<div class="form-inline">
<div class="mr-3 mt-2">Item ID: </div>
<input class="form-control mt-2 col" name="itemID" maxlength="12" v-model="sale.itemID">
</div>
<div class="form-inline">
<div class="mr-2 mt-2">Quantity: </div>
<input type="number" min="1" class="form-control mt-2 col" placeholder="Quantity" name="itemQty" v-model="sale.itemQty">
</div>
</div>
</div>
<div class="updatesale" style="margin:0 auto; text-align: center;">
<button class="btn btn-success mt-2" type="button" name="button" v-on:click="updateSalesRec(sale.id)">Update</button>
</div>
</form>
</div>
Hope this is useful.
Did not make any differences. However I did notice something with my delete function. public function destroy(Request $req, $id) { $sales = Sales::find($id); $sales->delete(); return redirect()->action('pagesController@dSales'); } This works although I do get 500 internal sever error
– ahpenggggg
Nov 25 '18 at 17:43
Found the error. Apparently Im sending null data even with the new input so i get Integrity Violation Error. What do I do with this>
– ahpenggggg
Nov 25 '18 at 17:51
Which field is submitting the null data? You can set the value before it is submitted, or set a default value on database. If you have some constrains on the database field (like unique), then you either remove the constraint or ensure it is always satisfied.
– Elisha Senoo
Nov 25 '18 at 17:55
All fields. The default value of database is fine as I can do initial post request to have my data submitted. This however, my edited data does not get accepted and is submitted as null. How do I make sure upon clearing the existing data from the field, then the newly input data is being set ?
– ahpenggggg
Nov 25 '18 at 18:22
add a comment |
You don't need to create another instance of the Sales
object after finding it:
public function update(Request $req, $id){
$sales = Sales::find($id);
$sales->itemQty = $req['itemQty'];
$sales->itemID = $req['itemID'];
$sales->save();
}
I don't think your intention is to have your data submitted in array. So remove from the input field names:
<div class="card-body" v-for="(sale, index) in sales" :key="sale.id">
<form action="/Sales" method="post">
<div>
<input type="hidden" name="_token" :value="csrf">
<div class="form-group">
<div class="form-inline">
<div class="mr-3 mt-2">Item ID: </div>
<input class="form-control mt-2 col" name="itemID" maxlength="12" v-model="sale.itemID">
</div>
<div class="form-inline">
<div class="mr-2 mt-2">Quantity: </div>
<input type="number" min="1" class="form-control mt-2 col" placeholder="Quantity" name="itemQty" v-model="sale.itemQty">
</div>
</div>
</div>
<div class="updatesale" style="margin:0 auto; text-align: center;">
<button class="btn btn-success mt-2" type="button" name="button" v-on:click="updateSalesRec(sale.id)">Update</button>
</div>
</form>
</div>
Hope this is useful.
Did not make any differences. However I did notice something with my delete function. public function destroy(Request $req, $id) { $sales = Sales::find($id); $sales->delete(); return redirect()->action('pagesController@dSales'); } This works although I do get 500 internal sever error
– ahpenggggg
Nov 25 '18 at 17:43
Found the error. Apparently Im sending null data even with the new input so i get Integrity Violation Error. What do I do with this>
– ahpenggggg
Nov 25 '18 at 17:51
Which field is submitting the null data? You can set the value before it is submitted, or set a default value on database. If you have some constrains on the database field (like unique), then you either remove the constraint or ensure it is always satisfied.
– Elisha Senoo
Nov 25 '18 at 17:55
All fields. The default value of database is fine as I can do initial post request to have my data submitted. This however, my edited data does not get accepted and is submitted as null. How do I make sure upon clearing the existing data from the field, then the newly input data is being set ?
– ahpenggggg
Nov 25 '18 at 18:22
add a comment |
You don't need to create another instance of the Sales
object after finding it:
public function update(Request $req, $id){
$sales = Sales::find($id);
$sales->itemQty = $req['itemQty'];
$sales->itemID = $req['itemID'];
$sales->save();
}
I don't think your intention is to have your data submitted in array. So remove from the input field names:
<div class="card-body" v-for="(sale, index) in sales" :key="sale.id">
<form action="/Sales" method="post">
<div>
<input type="hidden" name="_token" :value="csrf">
<div class="form-group">
<div class="form-inline">
<div class="mr-3 mt-2">Item ID: </div>
<input class="form-control mt-2 col" name="itemID" maxlength="12" v-model="sale.itemID">
</div>
<div class="form-inline">
<div class="mr-2 mt-2">Quantity: </div>
<input type="number" min="1" class="form-control mt-2 col" placeholder="Quantity" name="itemQty" v-model="sale.itemQty">
</div>
</div>
</div>
<div class="updatesale" style="margin:0 auto; text-align: center;">
<button class="btn btn-success mt-2" type="button" name="button" v-on:click="updateSalesRec(sale.id)">Update</button>
</div>
</form>
</div>
Hope this is useful.
You don't need to create another instance of the Sales
object after finding it:
public function update(Request $req, $id){
$sales = Sales::find($id);
$sales->itemQty = $req['itemQty'];
$sales->itemID = $req['itemID'];
$sales->save();
}
I don't think your intention is to have your data submitted in array. So remove from the input field names:
<div class="card-body" v-for="(sale, index) in sales" :key="sale.id">
<form action="/Sales" method="post">
<div>
<input type="hidden" name="_token" :value="csrf">
<div class="form-group">
<div class="form-inline">
<div class="mr-3 mt-2">Item ID: </div>
<input class="form-control mt-2 col" name="itemID" maxlength="12" v-model="sale.itemID">
</div>
<div class="form-inline">
<div class="mr-2 mt-2">Quantity: </div>
<input type="number" min="1" class="form-control mt-2 col" placeholder="Quantity" name="itemQty" v-model="sale.itemQty">
</div>
</div>
</div>
<div class="updatesale" style="margin:0 auto; text-align: center;">
<button class="btn btn-success mt-2" type="button" name="button" v-on:click="updateSalesRec(sale.id)">Update</button>
</div>
</form>
</div>
Hope this is useful.
answered Nov 25 '18 at 17:06
Elisha SenooElisha Senoo
1,1742817
1,1742817
Did not make any differences. However I did notice something with my delete function. public function destroy(Request $req, $id) { $sales = Sales::find($id); $sales->delete(); return redirect()->action('pagesController@dSales'); } This works although I do get 500 internal sever error
– ahpenggggg
Nov 25 '18 at 17:43
Found the error. Apparently Im sending null data even with the new input so i get Integrity Violation Error. What do I do with this>
– ahpenggggg
Nov 25 '18 at 17:51
Which field is submitting the null data? You can set the value before it is submitted, or set a default value on database. If you have some constrains on the database field (like unique), then you either remove the constraint or ensure it is always satisfied.
– Elisha Senoo
Nov 25 '18 at 17:55
All fields. The default value of database is fine as I can do initial post request to have my data submitted. This however, my edited data does not get accepted and is submitted as null. How do I make sure upon clearing the existing data from the field, then the newly input data is being set ?
– ahpenggggg
Nov 25 '18 at 18:22
add a comment |
Did not make any differences. However I did notice something with my delete function. public function destroy(Request $req, $id) { $sales = Sales::find($id); $sales->delete(); return redirect()->action('pagesController@dSales'); } This works although I do get 500 internal sever error
– ahpenggggg
Nov 25 '18 at 17:43
Found the error. Apparently Im sending null data even with the new input so i get Integrity Violation Error. What do I do with this>
– ahpenggggg
Nov 25 '18 at 17:51
Which field is submitting the null data? You can set the value before it is submitted, or set a default value on database. If you have some constrains on the database field (like unique), then you either remove the constraint or ensure it is always satisfied.
– Elisha Senoo
Nov 25 '18 at 17:55
All fields. The default value of database is fine as I can do initial post request to have my data submitted. This however, my edited data does not get accepted and is submitted as null. How do I make sure upon clearing the existing data from the field, then the newly input data is being set ?
– ahpenggggg
Nov 25 '18 at 18:22
Did not make any differences. However I did notice something with my delete function. public function destroy(Request $req, $id) { $sales = Sales::find($id); $sales->delete(); return redirect()->action('pagesController@dSales'); } This works although I do get 500 internal sever error
– ahpenggggg
Nov 25 '18 at 17:43
Did not make any differences. However I did notice something with my delete function. public function destroy(Request $req, $id) { $sales = Sales::find($id); $sales->delete(); return redirect()->action('pagesController@dSales'); } This works although I do get 500 internal sever error
– ahpenggggg
Nov 25 '18 at 17:43
Found the error. Apparently Im sending null data even with the new input so i get Integrity Violation Error. What do I do with this>
– ahpenggggg
Nov 25 '18 at 17:51
Found the error. Apparently Im sending null data even with the new input so i get Integrity Violation Error. What do I do with this>
– ahpenggggg
Nov 25 '18 at 17:51
Which field is submitting the null data? You can set the value before it is submitted, or set a default value on database. If you have some constrains on the database field (like unique), then you either remove the constraint or ensure it is always satisfied.
– Elisha Senoo
Nov 25 '18 at 17:55
Which field is submitting the null data? You can set the value before it is submitted, or set a default value on database. If you have some constrains on the database field (like unique), then you either remove the constraint or ensure it is always satisfied.
– Elisha Senoo
Nov 25 '18 at 17:55
All fields. The default value of database is fine as I can do initial post request to have my data submitted. This however, my edited data does not get accepted and is submitted as null. How do I make sure upon clearing the existing data from the field, then the newly input data is being set ?
– ahpenggggg
Nov 25 '18 at 18:22
All fields. The default value of database is fine as I can do initial post request to have my data submitted. This however, my edited data does not get accepted and is submitted as null. How do I make sure upon clearing the existing data from the field, then the newly input data is being set ?
– ahpenggggg
Nov 25 '18 at 18:22
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53469462%2fhttp-request-500-internal-server-error-on-axios-put%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please show the exact error
– Elisha Senoo
Nov 25 '18 at 17:01
How do I get the exact error?
– ahpenggggg
Nov 25 '18 at 17:40