Group_concat - laravel eloquent

user3481058 picture user3481058 · Sep 15, 2014 · Viewed 23.5k times · Source

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 :)

Answer

user3481058 picture user3481058 · Sep 15, 2014

I just used:

use DB;

and in my query I used

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