Performance is a Journey

In Laravel, the N+1 problem is the silent killer of performance. But Eager Loading using with() is just the beginning.

1. Specific Select Queries

Instead of fetching all columns, only fetch what you need:

$posts = Post::select('id', 'title', 'slug')-\u003ewith('author:id,name')-\u003eget();

2. Lazy Eager Loading

If you need to load a relationship based on a condition:

$posts-\u003eloadCount('comments');

3. Query Caching

Cache heavy result sets:

$users = Cache::remember('active_users', 3600, fn() =\u003e User::active()-\u003eget());