In my Laravel, Vue JS application, I'm getting this type of error after I transferred my application to our server.
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:
- This error only happens if I tried to access the application from a server using other devices.
- Error occurs irregularly. If it doesn't show on first, sometimes shows-up after 2 or more ajax request.
- I'm using vForm for my ajax request.
- It works fine on my pc/localhost.
- It works fine as well when I tried to access my application inside my server. I mean, I tried to use the browser inside our server and it works with no problem.
PS.
- I checked my Request Header and
X-CSRF-TOKEN
is there. - In my Request Payload
_token
is there as well.
Below are my codes:
VueJS Method:
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'];
}
Thank you in advance!