Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent

In my blog application there users can post articles and comments on there. When I go to any user profile http://eloquent-laravel.app/user/Name then I want to eagerly loaded all articles and comments of that certain user. Here's my code but it's not eagerly loading all articles and comments.

How can I eagerly loaded these articles and comments? Thanks

$user = \App\User::with(['articles', 'comments'])->where('name', $name)->first(); return view('articles.user', compact('user'))->render();

Last updated 3 years ago.
0

try \App\User::with('articles.comments')

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ohid ohid Joined 23 Mar 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.