Missing Eager Load (ARCH7051)
Esta página aún no está disponible en tu idioma.
Key php.orm.missing-eager-load · Severity warning · Category orm
Running a query that will iterate related data without declaring eager loading (with) is the canonical cause of N+1. Eager loading batches relations into a single query.
Incorrect
Section titled “Incorrect”<?php$orders = Order::where('status', 'paid')->get();foreach ($orders as $order) { echo $order->customer->email; // lazy load, N queries}Correct
Section titled “Correct”<?php$orders = Order::with('customer') ->where('status', 'paid') ->get();foreach ($orders as $order) { echo $order->customer->email;}Add with() to the query for every relation accessed in the loop.