带有 Xdebug 的 Laravel 5 总是抛出“有效载荷无效”。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47355311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:58:42  来源:igfitidea点击:

Laravel 5 with Xdebug always throws "The payload is invalid."

phplaravelxdebug

提问by Dyego Nery

I configured Xdebug on VScode to debug my laravel application. But, when I start to debug, laravel always throws this error: Exception has occurred. Illuminate\Contracts\Encryption\DecryptException: The payload is invalid.

我在 VScode 上配置了 Xdebug 来调试我的 Laravel 应用程序。但是,当我开始调试时,laravel 总是抛出这个错误:Exception has occurred. Illuminate\Contracts\Encryption\DecryptException: The payload is invalid.

I already tried to run php artisan optimize.

我已经尝试运行php artisan optimize.

Anyone here already faced this issue? I'm using Laravel 5.5

这里有人已经遇到过这个问题吗?我正在使用 Laravel 5.5

Ps. I tried to debug a Laravel 4 application. It worked without any issues. So, I think it may be something specific for Laravel 5.

附言。我试图调试 Laravel 4 应用程序。它没有任何问题。所以,我认为这可能是 Laravel 5 的特定内容。

回答by Jon

By default Laravel will encrypt, and subsequently also decrypt, all cookies on a request.

默认情况下,Laravel 会加密并解密请求中的所有 cookie。

When using Xdebug to debug your application from a browser, a cookie called "XDEBUG_SESSION" is set. As this cookie was not set, and thus not encrypted, by the Laravel framework, an error will be thrown when the framework automatically detects and tries to decrypt the cookie.

当使用 Xdebug 从浏览器调试您的应用程序时,会设置一个名为“XDEBUG_SESSION”的 cookie。由于 Laravel 框架未设置此 cookie,因此未加密,因此当框架自动检测并尝试解密 cookie 时,将抛出错误。

The correct solution is to just add the "XDEBUG_SESSION" cookie to the exceptions array in the App\Http\Middleware\EncryptCookiesmiddleware.

正确的解决方案是将“XDEBUG_SESSION”cookie 添加到App\Http\Middleware\EncryptCookies中间件的异常数组中。

/**
 * The names of the cookies that should not be encrypted.
 *
 * @var array
 */
protected $except = [
    'XDEBUG_SESSION'
];

回答by Vrutin Rathod

If the answer doesn't work, try adding this into launch.json

如果答案不起作用,请尝试将其添加到 launch.json

{
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9001,
        "ignore": [
            "**/vendor/**/*.php"
        ]
    },

More info: https://stackoverflow.com/a/49795318/1998033

更多信息https: //stackoverflow.com/a/49795318/1998033

回答by Dyego Nery

The @ceejayoz comment solved the issue. I run php artisan otimize, and the clear all my cookies on the browser, and it started to work properly.

@ceejayoz 评论解决了这个问题。我运行 php artisan otimize,并清除浏览器上的所有 cookie,它开始正常工作。

回答by bdebever

As far as I am concerned, I also had to turn off the Exceptionsand Everythingfrom being reported, or else, the issue persisted.

就我而言,我还必须关闭ExceptionsEverything以免被报告,否则问题仍然存在。

回答by Efrén

This my solution. I'm using VsCode and the file configuration xdebug (launch.json) must be match to workspace

这是我的解决方案。我正在使用 VsCode 并且文件配置 xdebug (launch.json) 必须与工作区匹配

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "log":true,
        "pathMappings": {

           // "serverSourceRoot": "/var/www/html",
            //"localSourceRoot": "${workspaceRoot}"
            "/var/www/html":"/Users/{username}/sites/{mysitefolder}"

        },
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9000
    }
]

}

}

回答by Homer

Temporarily commented out \App\Http\Middleware\EncryptCookies::class, which is inside of the web middlewareGroups of app/Http/Kernel. Solved my issue with this. Do need to remember turn it back though. Any better solutions from anyone? I tried the above mentioned methods, no one worked for me, unfortunately.

暂时注释掉了\App\Http\Middleware\EncryptCookies::class,它在app/Http/Kernel的web middlewareGroups里面。解决了我的问题。确实需要记住把它转回来。任何人有更好的解决方案吗?我尝试了上述方法,不幸的是,没有人对我来说有效。