Skip to content

GroupBy with count does not work #3512

Description

@mshamaseen
  • Laravel-mongodb Version: 5.7
  • PHP Version: 8.4

Description:

Message::where('broadcast_id', 3)->groupBy('status')->count();

result to
WARNING Object of class Illuminate\Support\Collection could not be converted to int in vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php on line 3932.

and the return value is always 1.

The reason for that is:

if ($this->groups) {

It returns a collection if groupBy exists.

whereas Laravel count function on vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:3932 expects a number.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions