Skip to content

countBy method fails if the field name is passed as a string #33847

@linktoahref

Description

@linktoahref
  • Laravel Version: 7.25.0
  • PHP Version: 7.2.33
  • Database Driver & Version: mysql & 8.0.21

Description:

With respect to the commit #33801
Returns error "Called to undefined function " on countBy method if the field name is passed as a string.

Steps To Reproduce:

Laravel version 7.24.0

$collection = collect([
    ['type' => 'O+', 'name' => 'John'],
    ['type' => 'O-', 'name' => 'Joe'],
    ['type' => 'O+', 'name' => 'Justin']
]);

$collection->countBy('type');

// returns
Illuminate\Support\Collection {#4859
    all: [
        "O+" => 2,
        "O-" => 1,
    ],
}

Laravel version 7.25.0

$collection = collect([
    ['type' => 'O+', 'name' => 'John'],
    ['type' => 'O-', 'name' => 'Joe'],
    ['type' => 'O+', 'name' => 'Justin']
]);

$collection->countBy('type');

// returns
Call to undefined function type() in vendor/laravel/framework/src/Illuminate/Support/LazyCollection.php on line 259

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions