laravel/framework — pull request #1113 by miguelbgouveia (2013-04-30 09:23:24+00:00)
Title: Error when aggregate query return no results

When using a query with groupBy that return no results I was getting the following error:

ErrorException: Notice: Undefined offset: 0 in .../vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php line 1101

Example:
Users::groupBy(‘name’)->having(‘aggregate’, ’>‘, 2)->count();

To resolve this issue we change the Illuminate\Database\Query/Builder->aggregate() function to test if exists results for the query. If no results exist the function returns null avoiding throw an error.