Executive Summary: How to use Eloquent effectively without triggering N+1 issues and server crashes.
In platforms like Solidrix Send and WhatsMeet, reading from the database is the biggest bottleneck.
### The N+1 Problem
The most common mistake in Laravel is looping through relationships without eager loading:
```php
// BAD: Triggers 101 queries for 100 subscribers
$subscribers = Subscriber::all();
foreach ($subscribers as $sub) {
echo $sub->campaign->name;
}
// GOOD: Triggers only 2 queries
$subscribers = Subscriber::with('campaign')->get();
```
### Indexing
Always add indexes to columns that are frequently used in `WHERE` clauses. If you filter by `tenant_id` and `status` constantly, create a composite index in your migration:
`$table->index(['tenant_id', 'status']);`