在我的Laravel,VUE JS应用程序中,当我把我的应用程序转入服务器时,我得到了这种类型的错误。
symfony\component\httpkernel\exception\httpexception
我看到了同样的问题,但是没有答案。我希望这次会有人能为这种错误提供答案或解决方案。
注:
只有当我试图使用其他设备从服务器访问应用程序时,才会发生此错误。
错误是不规则发生的。如果它不首先显示,有时在2个或多个Ajax请求之后出现。
我使用here来处理ajax请求。
它在我的pc/localhost上运行良好。
当我试图访问服务器内的应用程序时,它也工作得很好。我是说,我试着在我们的服务器中使用浏览器,它工作正常。
附言。
我检查了我的请求头,找到了。
在我的请求中,payloadX-CSRF-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 Controller:
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'];
}
提前谢谢你!
最佳答案
检查storage/log/laravel.log
文件是否存在。他们也有写/读的权限
通过运行以下命令可以很容易地解决此问题:
sudo chmod -R 777 storage/logs