Group_concat - laravel eloquent
or just replace
->select('commands.username','**group_concat(products.name)**')
with
->selectRaw('commands.username, **group_concat(products.name)**')
This worked for me
$list = TableName::where('user_id', 'user_001'
->groupBy('user_id')
->groupBy('subscription_id')
->select('user_id','subscription_id','type')
->selectRaw('GROUP_CONCAT(holiday) as holidays')
->get();
or
use Illuminate\Support\Facades\DB;
$sql = 'SELECT GROUP_CONCAT(holiday) as holidays, user_id,subscription_id, type FROM TableName
where vendor_id = 'user_001' GROUP BY user_id, subscription_id;';
$list = DB::select($sql, []);
I just used:
use DB;
and in my query I used
DB::raw('group_concat(products.name)')
Best example for it..
ModelName::select('ID', DB::raw('CONCAT(First_Name, " ", Last_Name) AS full_name')) ->get() ->toArray(); Result Jon Doe,Jeffery Way,Tailer,taylor otwell