GROUP_CONCAT with different SEPARATOR in laravel Example
In this post we will give you information about GROUP_CONCAT with different SEPARATOR in laravel Example. Hear we will give you detail about GROUP_CONCAT with different SEPARATOR in laravel ExampleAnd how to use it also give you demo for it if it is necessary.
Whenever, you need to use GROUP_CONCAT with differente separator(I mean default separator is ‘,’, But you want to change ‘@’,’#’,’&’ etc as you want). then you have to use use SEPARATOR keyword in GROUP_CONCAT(). If you are working on laravel then you have to also use DB::raw() for write GROUP_CONCAT() inside the this function.
So, Basically how to change seprator in group_concat(), In following example i change ‘,’ separator into ‘@’.you can use the following example how to use in laravel 4 and 5.
Example:
$items = DB::table('items')
->select("items.id","items.name"
,DB::raw("(GROUP_CONCAT(items_city.name SEPARATOR '@')) as 'cities'"))
->leftjoin("items_city","items_city.item_id","=","items.id")
->groupBy('items.id')
->get();
Try this…..
Hope this code and post will helped you for implement GROUP_CONCAT with different SEPARATOR in laravel Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs