Use dot-notation strings inside with() to eager load deeply nested relationships in single database query chains.
When fetching models that require multi-level relationships (e.g. Posts -> Comments -> Author), use dot-notation strings in with() to eager load all levels efficiently.
use App\Models\Post;
// Eager loads post author, comments, and comment authors
$posts = Post::with(['author', 'comments.author'])->get();
- Eager loads multi-level nested relationships cleanly in dot-notation strings
- Prevents cascading N+1 query problems across nested views
- Allows applying constraints to nested levels using array key closures
Related Tips
View all tips →Scope Pivot Table Queries with Closures in wherePivot() in Laravel 13.26
Laravel 13.26 allows wherePivot() and orWherePivot() to accept closures, enabling direct reuse of local scopes defined on custom Pivot models.
Remove Global Eager Loading with withoutRelation()
Use withoutRelation() or unsetRelation() to remove eager loaded relationships on specific Eloquent queries or model instances.