Lazy Eager Loading

When you learn what to load only after the query, load() eager loads onto models you already hold, and loadMissing() skips relationships already present. Both take with() syntax:

loadMissing() reuses what is loaded; load() queries againSQL
use App\Models\Order;
DB::listen(fn ($q) => print('-- '.wordwrap($q->toRawSql(), 88, "\n   ").PHP_EOL));
$orders = Order::with('customer:id,name')->where('status', 'paid')->simplePaginate(3);
$orders->loadMissing(['customer:id,name', 'customer.reviews:id,customer_id,rating']);
$orders->load('customer:id,name');
echo 'reviews: ', json_encode($orders->first()->customer->relationLoaded('reviews')), "\n";
Output
-- select * from `orders` where `status` = 'paid' limit 4 offset 0
-- select `id`, `name` from `customers` where `customers`.`id` in (2, 3, 6, 222)
-- select `id`, `customer_id`, `rating` from `reviews` where `reviews`.`customer_id` in (2,
   3, 6)
-- select `id`, `name` from `customers` where `customers`.`id` in (2, 3, 6)
reviews: false

simplePaginate() reads one extra order (customer 222's) to learn whether a next page exists. loadMissing() kept the customers and fetched only their reviews; load() fetched the customers again and replaced them, discarding those reviews. Prefer loadMissing() in shared code such as API resources.