Skip to content

Accept a plain model in Eloquent Collection identity methods on pivot-shaped collections #2363

Open

Description

@alies-dev

Follow-up to #2348 / #2360.

Since #2360, BelongsToMany / MorphToMany relation properties are Collection<int, M&object{pivot: P}>. Eloquent Collection's identity methods then reject a plain model, although Laravel compares by key (is()):

$contact->labels->contains($label);                 // ImplicitToStringCast (monica)
$move->moveDestinations->diff(collect([$pushed]));  // PossiblyInvalidArgument (aureuserp)

The same already happens for ->get() results on Laravel 13.41+. Proposal: let the model-comparing params of contains(), doesntContain(), diff(), intersect() (and similar) in the Eloquent Collection stub accept TModel|\Illuminate\Database\Eloquent\Model. Related: #1860.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions