You have to use joins for that
$users = User::select('users.name, users.age, comments.comment')
->join('comments', 'users.id', '=', 'comments.user_id')
->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I build a query and loaded relationships with it then select some columns from a model but want to add/select more columns from related modes/relationships.
for example $user = User::with('comments') ->select('name', 'age') ->addSelect('comment') // i want to add columns from comments model. ->get();
is there any way to select column at this point ?
So
$users = User::with('comments:id,user_id,comment')->get();
https://laravel.com/docs/8.x/eloquent-relationships#eager-loading-specific-columns
Please or to participate in this conversation.