use Illuminate\Database\Eloquent\Model; public function boot(): void { // Loud in local and staging, silent in production Model::preventLazyLoading(! app()->isProduction()); } // Then the fix is mechanical: $posts = Post::query() ->with(['author:id,name', 'tags:id,name']) // only the columns used ->withCount('comments') // a count, not the rows ->latest() ->paginate(20); // Writing while iterating? chunkById, never chunk — chunk() shifts its // own offsets when the rows it already passed are modified. Post::where('needs_reindex', true) ->chunkById(500, fn ($rows) => $rows->each->reindex());