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

Displaying objects data views #1414

Open
max13fr opened this issue May 9, 2023 · 2 comments
Open

Displaying objects data views #1414

max13fr opened this issue May 9, 2023 · 2 comments

Comments

@max13fr
Copy link

max13fr commented May 9, 2023

Hello,

Thanks for debugbar that is really useful !

I just have an issue with the view data collector that is not displaying objects but only the class name (even with options.views.data = true) :

image

It's really annoying because a lot of data are class in Laravel, like the models.

I tried a little fix in vendor/barryvdh/laravel-debugbar/src/DataCollector/ViewCollector.php (line 137) :

        if (!$this->collect_data) {
            $params = array_keys($view->getData());
        } else {
            $data = [];
            foreach ($view->getData() as $key => $value) {
                // current :
                // $data[$key] = $this->getDataFormatter()->formatVar($value);
                // test using json_encode() :
                $data[$key] = json_encode($value, JSON_PRETTY_PRINT);
            }
            $params = $data;
        }

image

What do you think about the idea ?
Obviously, it's perfectible, it's just a POC, I think we should try to improve the DataFormatter, it's just to show an example of what I would like to see.

Thanks in advance,
Max

@parallels999
Copy link
Contributor

Too much data, and your code is wrong, it should be something like this

if (!$this->collect_data) {
    $params = array_keys($view->getData());
} else {
    $data = [];
    foreach ($view->getData() as $key => $value) {
        if (is_object($value) && method_exists($value, 'toArray')) {
            $value = ['class' => $value] + $value->toArray();
        }

        $data[$key] = $this->getDataFormatter()->formatVar($value);
    }
    $params = $data;
}

@asfaqahmed
Copy link

Did you solve this issue

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

3 participants