Group by multiple columns in Laravel

前端 未结 4 686
小鲜肉
小鲜肉 2020-12-09 15:41

How to GROUP BY multiple column in Laravel? I tried this code:

$routes = DB::table(\'route\')
    ->groupBy(\'rte_origin\')
    ->groupBy(         


        
4条回答
  •  情书的邮戳
    2020-12-09 16:08

    Did you try:

    $routes = DB::table('route')
    ->groupBy('rte_origin', 'rte_destination')
    ->get();
    

    Can't test here right now, but the API says groupBy() accepts an array.

    For reference, please visit:

    • Laravel 5.0: https://github.com/laravel/framework/blob/5.0/src/Illuminate/Database/Query/Builder.php#L1037
    • Laravel 4.2: https://github.com/laravel/framework/blob/4.2/src/Illuminate/Database/Query/Builder.php#L1017

提交回复
热议问题