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 :)
The GROUP_CONCAT() function in MySQL is used to concatenate data from multiple rows into one field. This is an aggregate (GROUP BY) function which returns a String value, if the group contains at least one non-NULL value. Otherwise, it returns NULL.
Your answerUse table_name. * in select to get all the fields. $assignment_details = $assignment->raw_plan() ->select('raw_plans. *', DB::raw('group_concat(name) as names')) ->where('assignment_id', 1) ->groupBy('flag') ->get();
I just used:
use DB;
and in my query I used
DB::raw('group_concat(products.name)')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With