Here is an example to understand the concept of using group_concat() to join in Laravel. We have 3 tables like "dynamic_forms", "dynamic_forms_mapping", "categories".

BY Best Interview Question ON 12 Nov 2019

Example

$list = DB::table('dynamic_forms')
      ->select("dynamic_forms.*" ,DB::raw("(GROUP_CONCAT(wf_categories.name SEPARATOR ', ')) as category"))
      ->leftjoin("dynamic_forms_mapping", "dynamic_forms_mapping.form_id","=","dynamic_forms.id")
      ->leftjoin("categories", "dynamic_forms_mapping.category_id","=","categories.id")
      ->groupBy('dynamic_forms.id')
      ->where('dynamic_forms.status', 1)
      ->get();