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

Guido's avatar
Level 2

Eloquent Model $hidden for Relations

Hey, I'm trying to hide some specific information on a relation. Let's say I have an User model with the relation Role. Now, when I use User::with('roles')->all(); I don't want the created_at information for the roles.

I tried to do something like this in my User model: protected $hidden = ['roles.created_at']; but without success.

Anyone with an idea?

0 likes
1 reply

Please or to participate in this conversation.