Group By Eloquent ORM

前端 未结 3 1372
天涯浪人
天涯浪人 2020-12-10 00:47

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 sh

3条回答
  •  没有蜡笔的小新
    2020-12-10 01:33

    Laravel 5

    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();
    

提交回复
热议问题