laravel dump(), how to dump `model->attributes`?

682 views Asked by At

In my views i use a lot the @dump($model) method, its easy to see the model's attributes like that and build forms or display data.

I want now to dump only the attributes of the model, but I get null (I assume that it is because the attributes is protected property). is there a way to do it?

<some html && blade>
@dump($model); // works
@dump($model->attributes); // null
// also tried: @dump($model->attributes());
1

There are 1 answers

0
Olaolulode On

If you want to dump model attribute you might need to do something like this

$user = User::find(1);

dump($user->attributesToArray());

This will output an array of the user's attributes and their values in the browser.

in your case it would be

@dump($model->attributesToArray());