[英]Laravel "Symfony\Component\HttpKernel\Exception\HttpException" error
In my Laravel, Vue JS application, I'm getting this type of error after I transferred my application to our server.在我的 Laravel,Vue JS 应用程序中,我在将应用程序传输到我们的服务器后遇到了此类错误。
Symfony\Component\HttpKernel\Exception\HttpException
Symfony\Component\HttpKernel\Exception\HttpException
I saw the same problem here but there's no answer.我在这里看到了同样的问题,但没有答案。 I hope this time there will be someone that can provide an answer or solution for this type of error.
我希望这次会有人可以为此类错误提供答案或解决方案。
Note:笔记:
PS. PS。
X-CSRF-TOKEN
is there.X-CSRF-TOKEN
在那里。_token
is there as well._token
也在那里。 Below are my codes:以下是我的代码:
VueJS Method: 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: 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'];
}
Thank you in advance先感谢您
in your.env file make changes like this在 your.env 文件中进行这样的更改
APP_URL=http://your_server_url
or you have to put thin in your index.php
file或者你必须在你的
index.php
文件中放薄
header("Access-Control-Allow-Origin: http://localhost");
check in the resources/js/components folder in you component if you have如果有,请检查组件中的 resources/js/components 文件夹
http://127.0.0.1:8000/fetchusers
change it to将其更改为
fetch('fetchusers',{
method:'POST',
headers:{
'Content-Type':'application/json',
X_CSRF_TOKEN:('meta[name="csrf-token"]').content,
'Accept':'application/json'
}
})
it might help.它可能会有所帮助。
it's because of the csrf_token usually, you can check this documentation hope it will solve yours too.这是因为 csrf_token 通常,您可以查看此文档,希望它也能解决您的问题。
https://laravel.com/docs/5.6/csrf#csrf-x-csrf-token https://laravel.com/docs/5.6/csrf#csrf-x-csrf-token
To do: <meta name="csrf-token" content="{{ csrf_token() }}">
待办事项:
<meta name="csrf-token" content="{{ csrf_token() }}">
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});```
check your storage/log/laravel.log
file is there.检查您的
storage/log/laravel.log
文件是否存在。 Also they have permission to write/read他们也有写/读的权限
this can be fixed quite easily by running:这可以通过运行很容易地解决:
sudo chmod -R 777 storage/logs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.