Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addDataset Error #1719

Open
ARehmanMahi opened this issue Jan 23, 2025 · 0 comments
Open

addDataset Error #1719

ARehmanMahi opened this issue Jan 23, 2025 · 0 comments

Comments

@ARehmanMahi
Copy link

ARehmanMahi commented Jan 23, 2025

@barryvdh Hi, I just had the same error as This, I found one cause which is reproducible.

Laravel 11 fresh install.
using jetstream
ubuntu 24.04
php8.4.1
nginx

Route::group(['group' => RouteGroupEnum::ADMINISTRATION], function (): void {
    Route::resource('users', UserController::class);
});

RouteGroupEnum

declare(strict_types=1);

namespace App\Enums;

enum RouteGroupEnum
{
    case ADMINISTRATION;
}

using RouteGroupEnum::ADMINISTRATION as group attribute messes up debugbar:
phpdebugbar.addDataSet(, "X9e9f63880c3a1639bbcd79e4c852fa02");

if I use string type eneum it works, even if I use any other object/model class even new stdClass() it works.

Route::group(['group' => new stdClass()], function (): void {
    Route::resource('users', UserController::class);
});

Debuging

using your suggestion to find out the decode error I tried:

json_encode($data);
die(var_dump(json_last_error_msg()));

output: Non-backed enums can't be serialized by json_encode

Possible fix
Well it is not an issue with the bebugbar per say, rather how json_decode works.

So, keeping my Enum non-baked yet still providing json_encode way to serialze

declare(strict_types=1);

namespace App\Enums;

use JsonSerializable;

enum RouteGroupEnum implements JsonSerializable
{
    case ADMINISTRATION;

    public function jsonSerialize(): string
    {
        return match ($this) {
            self::ADMINISTRATION => 'ADMINISTRATION',
        };
    }
}

I'm not sure this is the way to go, chatgpt gave this solution, and it seems to be working again.
But this was quite some gymnastic for me, it would have helped if somehow debugbar had given me some insight.

You can close this issue however you see fit. Just wanted to share my found. I'm sure this could be obvious for senior devs, but I could not have figured out without your debug snippet and chatgpt

P.S. I end up making the Enum BackedEnum, as Laravel & Other Laravel packge depend and use BackedEnum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant