Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

I already tried to run php artisan optimize.

Anyone here already faced this issue? I'm using 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.

like image 229
Dyego Nery Avatar asked Nov 17 '17 16:11

Dyego Nery


2 Answers

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

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.

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

/**  * The names of the cookies that should not be encrypted.  *  * @var array  */ protected $except = [     'XDEBUG_SESSION' ]; 
like image 65
Jonathan Avatar answered Oct 06 '22 17:10

Jonathan


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

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

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

like image 33
Vrutin Rathod Avatar answered Oct 06 '22 16:10

Vrutin Rathod