Skip to content

[13.x] Fix whereBelongsTo() and whereAttachedTo() collection types - #62002

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:where-belongs-to-collection-types
Oct 14, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:where-belongs-to-collection-types

Conversation

@xurshudyan

Copy link
Copy Markdown
Contributor

Passing a collection to whereBelongsTo() works, but PHPStan reports an error:

$customers = Customer::where('vip', true)->get();

Order::whereBelongsTo($customers)->get();
// expects Collection<int, Model>|Model, Collection<int, Customer> given

This fixes the docblocks of whereBelongsTo(), whereAttachedTo() and their orWhere versions so a collection of any model is accepted.

@taylorotwell
taylorotwell merged commit 78a5c48 into laravel:13.x Oct 14, 2026
64 checks passed
binaryfire added a commit to hypervel/components-backup that referenced this pull request Oct 26, 2026
Apply laravel/framework#62002 (78a5c48ea3). Annotate belongs-to and attached-to predicates, including their or variants, with covariant model collection parameters. Port all six builder type assertions without changing query execution. Formatting and full source and type 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