问题描述
这是我的控制器
public function PoststatusChange(Request $request,$Id)
{
$value = $request->Id;
//$tripid = $request->tripid;
$tripid = $Id;
$data = SaveReportData::where('tripid','=',$tripid)->first();
$datas = SaveReportData::where('Id',$data->Id)->first();
$f = SaveReportData::find($datas->Id);
if ($data->Id == $f->Id) {
$f->paymentstatus = $request->Id;
$s = $f->paymentstatus;
}
$f->save(); //Here Lies an Error When i commented this line i got my response back
$string = "";
if($f->paymentstatus == 1){
$string = "Your Status Changed to Paid!";
}
if($f->paymentstatus == 2){
$string = "Your Status Changed to Processing";
}
return response()->json($string);
}
这是我的路线
Route::post('statusChange/{Id}','HomeController@PoststatusChange');
这是我的阿贾克斯
function Report() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('Meta[name="csrf-token"]').attr('content')
}
});
var status = $('#status').val();
var tripid = $('#tripid').val();
console.log(status);
if(status != "" && tripid != ""){
$.ajax({
url: '/statusChange/'+tripid,type: "post",dataType: "json",cache:false,data: {
'_token': "{{ csrf_token() }}",'Id': status,'tripid': tripid,},success: function(response){// What to do if we succeed
alert(response);
}
});
}
}
我正在尝试获取 id 并通过 ajax 传递给控制器我得到了我的响应(数据),但是当我尝试使用 save() 函数将数据保存在数据库中时,它给了我 500 错误
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)