Search code examples
laraveleloquentgroup-concat

Group_concat - laravel eloquent


please I want to use group_concat in a query using eloquent and not raw queries.

here is the code which i tried to execute and did't work for me:

commands::join('products', 'products.id', '=','commands.idproduct')
->select('commands.username','**group_concat(products.name)**')
->group by ('commands. username')
->get();

Thanks in advance :)


Solution

  • I just used:

    use DB;

    and in my query I used

    DB::raw('group_concat(products.name)')