Skip to content

Eloquent/Collection: Call to a member function getKey() on string  #43015

Description

@LastDragon-ru

The following code works fine when collection contains models but will fail if Collection is empty :

(new \Illuminate\Database\Eloquent\Collection())->map(fn() => 'converts item to string')->intersect(['a']);

Maybe map() it should return base collection if empty?

return $result->contains(function ($item) {
return ! $item instanceof Model;
}) ? $result->toBase() : $result;

PS: Laravel v9.17.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions