Error: “Request failed with status code 500” when adding data





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Getting 500 error when adding category with image, made image nullable in table, so i could add Category name if errors occur. Show the possible error or mistake im making in this code, thanks beforehand:



This is my template part







        <div class="form-group">
<label>Name</label>
<input v-model="category.name" type="text" name="name" class="form-control">
</div>
<div class="form-group">
<label>Image</label>
<input type="file" class="form-control" @change="onChange" accept="image/*">
</div>

<div class="form-group">
<div class="col-md-6">
<input v-show="!edit" type="submit" class="btn btn-success btn-send" value="Add">
<input v-show="edit" type="submit" class="btn btn-success btn-send" value="Edit">
</div>
</div>
</div>
</div>




This is my route api



 Route::post('categories/store', function(Request $request){
return Category::create(['name' => $request->input(['name']),
['image' => $request->input(['image'])],
['created_at' => $request->input(['created_at'])]
]);
});


And this is vue js script



<script>
export default {
data: function() {
return {
edit: false,
list: ,
category: {
id: '',
name: '',
image: '',
created_at: '',
}
}
},
mounted: function() {
console.log('Category Component Loaded...');
this.fetchCategoryList();
},
methods: {
onChange(e) {
console.log(e.target.files[0])
var fileReader = new FileReader()
fileReader.readAsDataURL(e.target.files[0])
fileReader.upload = (e) => {
this.category.image = e.target.result
}
console.log(this.category)
},
createCategory: function() {
console.log('Creating category...');
let self = this;
let params = Object.assign({}, self.category);
axios.post('/api/categories/store', params)
.then(function() {
self.category.name = '';
self.category.image = '';
self.edit = false;
self.fetchCategoryList();
})
.catch(function(error) {
console.log(error);
});
},









share|improve this question























  • are you passing the CSRF_TOKEN or is the CSRF middleware turned off ?

    – Farrukh Ayyaz
    Nov 16 '18 at 20:46











  • you're not passing a parameter to your onChange function but it expects one.

    – Andrew1325
    Nov 16 '18 at 20:47






  • 1





    @Andrew1325 the parameter is passed by default, no need to set '@change="onChange($event)"'

    – Boussadjra Brahim
    Nov 16 '18 at 20:50











  • csrf_token is on

    – Ziyod
    Nov 16 '18 at 20:51











  • "500 error" is not a terribly helpful description. Your error logs will contain details of the actual problem.

    – miken32
    Nov 17 '18 at 4:14




















0















Getting 500 error when adding category with image, made image nullable in table, so i could add Category name if errors occur. Show the possible error or mistake im making in this code, thanks beforehand:



This is my template part







        <div class="form-group">
<label>Name</label>
<input v-model="category.name" type="text" name="name" class="form-control">
</div>
<div class="form-group">
<label>Image</label>
<input type="file" class="form-control" @change="onChange" accept="image/*">
</div>

<div class="form-group">
<div class="col-md-6">
<input v-show="!edit" type="submit" class="btn btn-success btn-send" value="Add">
<input v-show="edit" type="submit" class="btn btn-success btn-send" value="Edit">
</div>
</div>
</div>
</div>




This is my route api



 Route::post('categories/store', function(Request $request){
return Category::create(['name' => $request->input(['name']),
['image' => $request->input(['image'])],
['created_at' => $request->input(['created_at'])]
]);
});


And this is vue js script



<script>
export default {
data: function() {
return {
edit: false,
list: ,
category: {
id: '',
name: '',
image: '',
created_at: '',
}
}
},
mounted: function() {
console.log('Category Component Loaded...');
this.fetchCategoryList();
},
methods: {
onChange(e) {
console.log(e.target.files[0])
var fileReader = new FileReader()
fileReader.readAsDataURL(e.target.files[0])
fileReader.upload = (e) => {
this.category.image = e.target.result
}
console.log(this.category)
},
createCategory: function() {
console.log('Creating category...');
let self = this;
let params = Object.assign({}, self.category);
axios.post('/api/categories/store', params)
.then(function() {
self.category.name = '';
self.category.image = '';
self.edit = false;
self.fetchCategoryList();
})
.catch(function(error) {
console.log(error);
});
},









share|improve this question























  • are you passing the CSRF_TOKEN or is the CSRF middleware turned off ?

    – Farrukh Ayyaz
    Nov 16 '18 at 20:46











  • you're not passing a parameter to your onChange function but it expects one.

    – Andrew1325
    Nov 16 '18 at 20:47






  • 1





    @Andrew1325 the parameter is passed by default, no need to set '@change="onChange($event)"'

    – Boussadjra Brahim
    Nov 16 '18 at 20:50











  • csrf_token is on

    – Ziyod
    Nov 16 '18 at 20:51











  • "500 error" is not a terribly helpful description. Your error logs will contain details of the actual problem.

    – miken32
    Nov 17 '18 at 4:14
















0












0








0








Getting 500 error when adding category with image, made image nullable in table, so i could add Category name if errors occur. Show the possible error or mistake im making in this code, thanks beforehand:



This is my template part







        <div class="form-group">
<label>Name</label>
<input v-model="category.name" type="text" name="name" class="form-control">
</div>
<div class="form-group">
<label>Image</label>
<input type="file" class="form-control" @change="onChange" accept="image/*">
</div>

<div class="form-group">
<div class="col-md-6">
<input v-show="!edit" type="submit" class="btn btn-success btn-send" value="Add">
<input v-show="edit" type="submit" class="btn btn-success btn-send" value="Edit">
</div>
</div>
</div>
</div>




This is my route api



 Route::post('categories/store', function(Request $request){
return Category::create(['name' => $request->input(['name']),
['image' => $request->input(['image'])],
['created_at' => $request->input(['created_at'])]
]);
});


And this is vue js script



<script>
export default {
data: function() {
return {
edit: false,
list: ,
category: {
id: '',
name: '',
image: '',
created_at: '',
}
}
},
mounted: function() {
console.log('Category Component Loaded...');
this.fetchCategoryList();
},
methods: {
onChange(e) {
console.log(e.target.files[0])
var fileReader = new FileReader()
fileReader.readAsDataURL(e.target.files[0])
fileReader.upload = (e) => {
this.category.image = e.target.result
}
console.log(this.category)
},
createCategory: function() {
console.log('Creating category...');
let self = this;
let params = Object.assign({}, self.category);
axios.post('/api/categories/store', params)
.then(function() {
self.category.name = '';
self.category.image = '';
self.edit = false;
self.fetchCategoryList();
})
.catch(function(error) {
console.log(error);
});
},









share|improve this question














Getting 500 error when adding category with image, made image nullable in table, so i could add Category name if errors occur. Show the possible error or mistake im making in this code, thanks beforehand:



This is my template part







        <div class="form-group">
<label>Name</label>
<input v-model="category.name" type="text" name="name" class="form-control">
</div>
<div class="form-group">
<label>Image</label>
<input type="file" class="form-control" @change="onChange" accept="image/*">
</div>

<div class="form-group">
<div class="col-md-6">
<input v-show="!edit" type="submit" class="btn btn-success btn-send" value="Add">
<input v-show="edit" type="submit" class="btn btn-success btn-send" value="Edit">
</div>
</div>
</div>
</div>




This is my route api



 Route::post('categories/store', function(Request $request){
return Category::create(['name' => $request->input(['name']),
['image' => $request->input(['image'])],
['created_at' => $request->input(['created_at'])]
]);
});


And this is vue js script



<script>
export default {
data: function() {
return {
edit: false,
list: ,
category: {
id: '',
name: '',
image: '',
created_at: '',
}
}
},
mounted: function() {
console.log('Category Component Loaded...');
this.fetchCategoryList();
},
methods: {
onChange(e) {
console.log(e.target.files[0])
var fileReader = new FileReader()
fileReader.readAsDataURL(e.target.files[0])
fileReader.upload = (e) => {
this.category.image = e.target.result
}
console.log(this.category)
},
createCategory: function() {
console.log('Creating category...');
let self = this;
let params = Object.assign({}, self.category);
axios.post('/api/categories/store', params)
.then(function() {
self.category.name = '';
self.category.image = '';
self.edit = false;
self.fetchCategoryList();
})
.catch(function(error) {
console.log(error);
});
},






laravel api vue.js






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 20:40









ZiyodZiyod

1




1













  • are you passing the CSRF_TOKEN or is the CSRF middleware turned off ?

    – Farrukh Ayyaz
    Nov 16 '18 at 20:46











  • you're not passing a parameter to your onChange function but it expects one.

    – Andrew1325
    Nov 16 '18 at 20:47






  • 1





    @Andrew1325 the parameter is passed by default, no need to set '@change="onChange($event)"'

    – Boussadjra Brahim
    Nov 16 '18 at 20:50











  • csrf_token is on

    – Ziyod
    Nov 16 '18 at 20:51











  • "500 error" is not a terribly helpful description. Your error logs will contain details of the actual problem.

    – miken32
    Nov 17 '18 at 4:14





















  • are you passing the CSRF_TOKEN or is the CSRF middleware turned off ?

    – Farrukh Ayyaz
    Nov 16 '18 at 20:46











  • you're not passing a parameter to your onChange function but it expects one.

    – Andrew1325
    Nov 16 '18 at 20:47






  • 1





    @Andrew1325 the parameter is passed by default, no need to set '@change="onChange($event)"'

    – Boussadjra Brahim
    Nov 16 '18 at 20:50











  • csrf_token is on

    – Ziyod
    Nov 16 '18 at 20:51











  • "500 error" is not a terribly helpful description. Your error logs will contain details of the actual problem.

    – miken32
    Nov 17 '18 at 4:14



















are you passing the CSRF_TOKEN or is the CSRF middleware turned off ?

– Farrukh Ayyaz
Nov 16 '18 at 20:46





are you passing the CSRF_TOKEN or is the CSRF middleware turned off ?

– Farrukh Ayyaz
Nov 16 '18 at 20:46













you're not passing a parameter to your onChange function but it expects one.

– Andrew1325
Nov 16 '18 at 20:47





you're not passing a parameter to your onChange function but it expects one.

– Andrew1325
Nov 16 '18 at 20:47




1




1





@Andrew1325 the parameter is passed by default, no need to set '@change="onChange($event)"'

– Boussadjra Brahim
Nov 16 '18 at 20:50





@Andrew1325 the parameter is passed by default, no need to set '@change="onChange($event)"'

– Boussadjra Brahim
Nov 16 '18 at 20:50













csrf_token is on

– Ziyod
Nov 16 '18 at 20:51





csrf_token is on

– Ziyod
Nov 16 '18 at 20:51













"500 error" is not a terribly helpful description. Your error logs will contain details of the actual problem.

– miken32
Nov 17 '18 at 4:14







"500 error" is not a terribly helpful description. Your error logs will contain details of the actual problem.

– miken32
Nov 17 '18 at 4:14














0






active

oldest

votes












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%2f53345079%2ferror-request-failed-with-status-code-500-when-adding-data%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53345079%2ferror-request-failed-with-status-code-500-when-adding-data%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

Bressuire

Vorschmack

Quarantine