Skip to content

[13.x] Skip building a query in loadMissing() when no relations are given - #61869

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
MAboyadak:fix/load-missing-no-relations
Oct 5, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
MAboyadak:fix/load-missing-no-relations

Conversation

@MAboyadak

Copy link
Copy Markdown

Since #56711 (12.27.0), Eloquent\Collection::loadMissing() builds a query from the first item before looking at the requested relations:

$query = $this->first()->newQueryWithoutRelationships()->with($relations);

Before that change, loadMissing([]) was a no-op. Now it always builds a query builder, even when there is nothing to load.

This matters for code that calls loadMissing() generically. For example, flugger/laravel-responder calls it on every Eloquent collection it transforms. When the collection holds non-model items (such as spatie/laravel-data's Data::collect(Model::all()), which keeps the Eloquent collection type), that now throws:

Call to undefined method App\Data\UserData::newQueryWithoutRelationships()

This PR returns early when no relations are given, restoring the pre-12.27 behavior for that case. Calls with relations are unchanged. A unit test asserts that no query is built for loadMissing([]).

@taylorotwell
taylorotwell merged commit 57b3e7d into laravel:13.x Oct 5, 2026
62 checks passed
binaryfire added a commit to hypervel/components-backup that referenced this pull request Oct 26, 2026
Apply laravel/framework#61869 (57b3e7d76b). Collection::loadMissing([]) returns the same collection without constructing a model query. The upstream regression rejects query construction. The database suite, formatting and full analysis pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants