8

I was config success to debug in PHP on VSCode.

My problem is when I run the project it always errors at the function:

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;
}

... from file: /srv/http/laravelproject/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php

I can't debug to breakpoint I was set.

Gif screen record: http://i.imgur.com/6pNkoHe.gif

Ave
  • 4,338
  • 4
  • 40
  • 67

4 Answers4

16

Had the same issue when using Docker with VsCode and xDebug in Laravel.

For anyone interested in a different approach (since Laravel 5.6 there is no optimize command anymore)

Just add the ignore section to your launch.json config.

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

Solved the issue for me.

Got this from Docker Github Repo

Krishan König
  • 462
  • 4
  • 10
5

Your question seems to be a related post to this, which provides a pretty good answer. Also, my question to you is why are you using DecryptException? Laravel has bcrypt(for password hashing) and csrf tokens (form data encryption) that are much easier to use.

For those looking for a quick answer without reading the comments:

Run these commands in Eloquent:

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

Robert Dewitt
  • 324
  • 5
  • 17
  • You can see this gif.http://i.imgur.com/6pNkoHe.gif. I don't use `DecryptException`. I think my error relationship with cookies when login. Your link provides only for setup debug. I know how to debug in VSCode and setup success. – Ave Jun 21 '17 at 08:33
  • Your image doesn't load - comes up as `404`. – Robert Dewitt Jun 21 '17 at 08:34
  • This might be a longshot, but hear me out. I had issues using the `Voyager` package before. First, try running `php artisan optimize` and see what happens. And then clear cache and cookies in the testing browser. – Robert Dewitt Jun 21 '17 at 08:38
  • So, the exception is thrown within VSCode and not when browsing the site? I find that weird. – Robert Dewitt Jun 21 '17 at 08:39
  • See if [**this post**](https://stackoverflow.com/questions/38327565/laravel-5-decryption-error-the-mac-is-invalid) helps as well. It mentions that it might be a server/redis issue. – Robert Dewitt Jun 21 '17 at 08:41
  • thanks for your link. seem all my effort with your help can't resolve. – Ave Jun 21 '17 at 08:51
  • hey. I try with: `php artisan optimize`. -> `php artisan cache:clear` -> `composer dump-autoload`. Clear all cache and cookies on my browser. It's working. Thanks @robertdewitt. – Ave Jun 21 '17 at 08:54
  • 1
    Anytime!! Wow, I almost didn't think that would work. But yeah, when in doubt, use `optimize`. It solves **A LOT** of issues. – Robert Dewitt Jun 21 '17 at 08:58
4

I had the same problem and the accepted answer solved it.

However, if anyone simply wants to dismiss the problem temporarily, rather than getting to the root of it, you can uncheck the "Everything" checkbox at the bottom of the Breakpoints panel of the debug pane, and that will skip over the error.

JP Lew
  • 4,121
  • 2
  • 32
  • 45
1

On Laravel 5.7, it works for me:

{
"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"
    }
]
}
Mexidense
  • 954
  • 8
  • 7