Skip to content

Illuminate\Database\Eloquent\Collection duplicates() doesn't work like Illuminate\Support\Collection #61595

Closed

Description

@parallels999

Laravel Version

13.x

PHP Version

8.3

Database Driver & Version

MariaDb

Description

The documentation states that Illuminate\Database\Eloquent\Collection extends all the methods of Illuminate\Support\Collection,
but attempting to use ->duplicates('some_attribute') throws an unexpected exception.

I only realized this when checking the sources; should it be documented that it can't be used, or is it a bug?

Steps To Reproduce

/*
MyModel{
  id, some_attribute
}
*/
$myList = MyModel::get();
$dup1 = collect($myList)->duplicates('some_attribute'); // this works,  base collection was used
$dup2 = $myList->duplicates('some_attribute'); // unexpected exception on `$a->is($b)` 

/**
* Get the comparison function to detect duplicates.
*
* @return callable(TModel, TModel): bool
*/
protected function duplicateComparator($strict)
{
return fn ($a, $b) => $a->is($b);

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