无法在laravel 5.2中查询json数据 [英] cant't query json data in laravel 5.2
本文介绍了无法在laravel 5.2中查询json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过laravel 5.2和vuejs制作一个地址簿应用程序,我的应用程序需要CRUD功能,我停留在Update部分,我通过ajax将数据发送到laravel我在laravel中获取数据,但是我无法更新行.这是我在vuejs中处理更新的方法:
I'm making a adressbook app via laravel 5.2 and vuejs, my app needs CRUD functionality, i stuck at Update part, i send the data via ajax to laravel and i get the data in laravel but i cant update rows. this is my method in vuejs that handle updating:
updatecontact:function(){
var contactid = this.editingcontact.id;
var contact update = JSON.stringify(this.editingcontact);
this.$http({url: '/adressbook/'+contactid, data: {contactupdate} , method: 'PATCH'})
.then(function (response) {
console.log(response);
}, function (response) {
// error callback
});
这是在laravel(是PUT)中处理ajax请求的方法
and this the method that handles ajax request in laravel(it's a PUT)
public function update(Request $request, $id)
{
$adressbook = Adressbook::findorFail($id);
$adressbook->save($request->all());
}
最后这是数据的样子:
contactupdate: "{"id":5,"companyName":"poolad","zamineKar":"test","tel":"44044440","fax":"44044422","email"}"
推荐答案
一种更好的方法是发送 this.editingcontact
作为数据:
A better way to do it would just be to send this.editingcontact
as the data:
updatecontact:function(){
var contactid = this.editingcontact.id;
this.$http({url: '/adressbook/'+contactid, data: this.editingcontact , method: 'PATCH'})
.then(function (response) {
console.log(response);
}, function (response) {
// error callback
});
然后此更新代码应起作用:
Then this update code should work:
public function update(Request $request, $id)
{
$adressbook = Adressbook::findOrFail($id);
$adressbook->update($request->all());
}
这篇关于无法在laravel 5.2中查询json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文