Laravel“ Symfony \ Component \ HttpKernel \ Exception \ HttpException”错误

时间:2018-09-26 07:57:33

标签: php ajax laravel vue.js

在我的Laravel Vue JS应用程序中,将我的应用程序转移到我们的服务器后出现了这种错误。

  

Symfony \ Component \ HttpKernel \ Exception \ HttpException

我看到了相同的问题here,但没有答案。我希望这次有人可以为此类错误提供答案或解决方案。

注意:

  1. 仅当我尝试使用其他设备从服务器访问应用程序时,才会发生此错误。
  2. 错误不定期发生。如果第一次没有显示,有时在两次或更多次ajax请求之后出现。
  3. 我正在将vForm用于我的ajax请求。
  4. 在我的PC /本地主机上正常工作。
  5. 当我尝试访问服务器中的应用程序时,它也可以正常工作。我的意思是,我尝试使用服务器内部的浏览器,并且浏览器没有问题。

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'];


    }

提前谢谢!

3 个答案:

答案 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'
            }
        })

可能会有所帮助。