在我的Laravel Vue JS应用程序中,将我的应用程序转移到我们的服务器后出现了这种错误。
Symfony \ Component \ HttpKernel \ Exception \ HttpException
我看到了相同的问题here,但没有答案。我希望这次有人可以为此类错误提供答案或解决方案。
注意:
PS。
X-CSRF-TOKEN
在那里。_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'];
}
提前谢谢!
答案 0 :(得分:0)
检查您的storage/log/laravel.log
文件是否存在。他们也有权写/读
可以通过运行以下命令很容易地解决此问题:
sudo chmod -R 777 storage/logs
答案 1 :(得分:0)
在.env文件中进行如下更改
APP_URL=http://your_server_url
或者您必须在index.php
文件中放一些薄
header("Access-Control-Allow-Origin: http://localhost");
答案 2 :(得分:0)
如果有
,请检查组件中的resources / js / components文件夹
http://127.0.0.1:8000/fetchusers
将其更改为
fetch('fetchusers',{
method:'POST',
headers:{
'Content-Type':'application/json',
X_CSRF_TOKEN:('meta[name="csrf-token"]').content,
'Accept':'application/json'
}
})
可能会有所帮助。