I was searching for making a
GROUP BY name Eloquent ORM docs but I haven't find anything, neither on google.
Does anyone know if it's possible ? or should I use query builder ?
This question is tagged with
~ Asked on 2014-03-21 14:52:42
Eloquent uses the query builder internally, so you can do:
$users = User::orderBy('name', 'desc') ->groupBy('count') ->having('count', '>', 100) ->get();
~ Answered on 2014-03-21 14:58:10
This is working for me (i use laravel 5.6).
$collection = MyModel::all()->groupBy('column');
If you want to convert the collection to plain php array, you can use toArray()
$array = MyModel::all()->groupBy('column')->toArray();
~ Answered on 2018-08-17 10:51:56