Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DiffLock's avatar

How do I know which attributes exists in a Model?

I'm new to Laravel.

Using Sanctum, when I use my /login route, I'm getting a "tokens" object returned with my user (because I'm doing some "tokens" maintenance in my AuthController).

I then learned that in my User Model, I can add "tokens" to $hidden. And now "tokens" object is no longer appearing in the /login response. Great!

But is there a way to see all the attributes that I could potentially use in $hidden or other places, within a Model?

Or is it only possible to figure out, by looking at the json responses coming from the controller? Like I did in this case.

Thanks for reading!

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

You can dd($user->getAttributes()) to see the raw User data as an array. $user->toArray() will show you the visible data (after Model Accessors etc.).

Consider Eloquent API Resources for defining the structure of your models in JSON responses rather than the hidden property on the model class.

1 like
DiffLock's avatar

Thank you for that, and the Eloquent API Resources tip, I will check it out :)

Please or to participate in this conversation.