Http request 500 internal server error on Axios put












0















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?










share|improve this question

























  • 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
















0















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?










share|improve this question

























  • 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














0












0








0








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer
























  • 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













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
});


}
});














draft saved

draft discarded


















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









0














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.






share|improve this answer
























  • 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


















0














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.






share|improve this answer
























  • 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
















0












0








0







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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





















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks