【发布时间】:2019-03-01 22:30:02
【问题描述】:
在我的 Laravel、Vue JS 应用程序中,我在将应用程序转移到我们的服务器后遇到了这种类型的错误。
Symfony\Component\HttpKernel\Exception\HttpException
我看到了同样的问题here,但没有答案。希望这次能有人为此类错误提供答案或解决方案。
注意:
- 仅当我尝试使用其他设备从服务器访问应用程序时才会出现此错误。
- 错误发生不定期。如果它没有首先显示,有时会在 2 个或更多 ajax 请求后显示。
- 我正在使用 vForm 处理我的 ajax 请求。
- 它在我的 pc/localhost 上运行良好。
- 当我尝试访问服务器内的应用程序时,它也可以正常工作。我的意思是,我尝试在我们的服务器中使用浏览器,它没有问题。
附言。
- 我检查了我的请求标头,
X-CSRF-TOKEN在那里。 - 在我的Request Payload中也有
_token。
以下是我的代码:
VueJS 方法:
UpdateDepartmentInfo(){
this.departmentToUpdate._token = this.$root.csrf;
this.requestUpdateDepartmentOnProgress = true;
this.departmentToUpdate.put('department/'+this.departmentToUpdate.id)
.then((response) => {
this.requestUpdateDepartmentOnProgress = false;
this.GetDepartmentList();
swal(
'Department Info. Saved!',
'Department information has been successfully updated to database!',
'success'
);
})
.catch((error) => {
this.requestUpdateDepartmentOnProgress = false;
if (error.response.status == 401) {
alert('User session has expired. Please login again.');
location.replace("/login");
}
});
}
Laravel 控制器:
public function update(Request $request, $id)
{
// Check if the department object from model if it exists
try{
$department = Department::findOrFail($id);
}catch(\Exception $e){
return response(['error' => 'The department you want to edit can\'t be found in the database!' ], 400);
}
// check if it was just the status was sent
if($request['newStat'] != null){
$department->status = $request['newStat'];
}else{
$this->validate($request,[
'name' => 'required|string|max:191',
'code' => 'required|string|max:10',
]);
$department->name = $request['name'];
$department->code = $request['code'];
$department->description = $request['description'];
$department->status = $request['status'];
}
$department->save();
return ['message' => 'ok'];
}
提前谢谢你!
【问题讨论】:
-
你可以添加堆栈跟踪吗?
-
你的
.envAPP_URL中有什么 -
@ShaielndraGupta -
APP_URL=http://localhost -
@cbaconnier - 我在
laravel.log中找不到错误或 stracktrace,但在此处的响应中是:(等等,我不知道如何附加屏幕截图) -
@cbaconnier - 我什至无法在此处粘贴跟踪响应,因为它太长了。