mir-backend-php-laravellisted
Install: claude install-skill anantbhandarkar/make-it-right
# /mir-backend-php-laravel · Make It Right (Laravel)
Bottom tier of the chain: `mir-backend` (generic gates) → `mir-backend-php` (Zend Engine runtime model) → **this** (Laravel/Eloquent library mechanics). Run the gates first; load the PHP runtime tier for the lifecycle/process model; reach for *this* at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. **Runtime-level concerns (shared-nothing lifecycle, FPM sizing, Octane state bleed, opcache, pconnect, error model) live in `mir-backend-php` — not here.**
**Stack assumed:** Laravel 10/11 · Eloquent ORM · MySQL or PostgreSQL · Redis · Laravel Queues (Horizon or plain `queue:work`). If the project uses a different queue driver or a raw PDO layer, note the divergence before applying these.
## The Laravel footguns AI walks into most
### 1. Eloquent N+1 — the silent query multiplier
Eloquent lazy-loads relationships on first access. Inside a loop over a collection, accessing `$order->items` for each order fires a separate SELECT per iteration — N orders produce N+1 queries total.
- **Fix:** eager-load with `with()` in the initial query. Use `Model::preventLazyLoading()` in `AppServiceProvider::boot()` during local/CI environments — it throws an exception the moment a lazy load is attempted, making N+1 impossible to miss before production.
```php
// WRONG — fires 1 + N queries (1 for orders, N for items)
$orders = Order::all();
foreach ($orders as $order) {
echo $order->items->count(); // lazy load