无法在Laravel项目中使用Visual Code进行调试

时间:2017-06-21 07:40:10

标签: php laravel debugging visual-studio-code

我在VSCode上用PHP调试是成功的。

我的问题是当我运行项目时,它总是在函数中出错:

protected function getJsonPayload($payload)
{
    $payload = json_decode(base64_decode($payload), true);

    // If the payload is not valid JSON or does not have the proper keys set we will
    // assume it is invalid and bail out of the routine since we will not be able
    // to decrypt the given value. We'll also check the MAC for this encryption.
    if (! $this->validPayload($payload)) {
        throw new DecryptException('The payload is invalid.');
    }

    if (! $this->validMac($payload)) {
        throw new DecryptException('The MAC is invalid.');
    }

    return $payload;
}

...来自档案:/srv/http/laravelproject/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php

我无法调试我设置的断点。

Gif屏幕记录:http://i.imgur.com/6pNkoHe.gif

4 个答案:

答案 0 :(得分:8)

在Laravel中使用Docker和VsCode以及xDebug时会出现同样的问题。

对于任何对不同方法感兴趣的人(因为Laravel 5.6不再有optimize命令)

只需将ignore部分添加到launch.json配置。

{
   "name": "Listen for XDebug",
   "type": "php",
   "request": "launch",
   "port": 9000,
   "pathMappings": {
       "/var/www/html": "${workspaceRoot}",
    },
    // add this
    "ignore": [
        "**/vendor/**/*.php"
    ]
},

为我解决了这个问题。

来自Docker Github Repo

答案 1 :(得分:5)

您的问题似乎是this的相关帖子,这提供了一个非常好的答案。另外,我的问题是你为什么使用DecryptException? Laravel具有bcrypt(用于密码哈希)和csrf tokens(表单数据加密),更易于使用。

对于那些在没有阅读评论的情况下寻求快速回答的人:

在Eloquent中运行这些命令:

php artisan optimize - > php artisan cache:clear - > composer dump-autoload

答案 2 :(得分:3)

我有同样的问题,接受的答案解决了它。

然而,如果有人只想暂时解决问题,而不是找到问题的根源,你可以取消选中" Everything"调试窗格“断点”面板底部的复选框,将跳过错误。

答案 3 :(得分:0)

在Laravel 5.7上,它对我有用:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "ignore": [
            "**/vendor/**/*.php"
        ]
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9000,
        "runtimeExecutable": "/usr/bin/php"
    }
]
}