countBy method fails if the field name is passed as a string #33847
Closed
Description
- 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