title: How to implement GROUP_CONCAT in Laravel model class?
body: <p>I'm using GROUP_CONCAT function to fetch multiple photo image paths for the selected professional in Laravel. The code is in a model class.
  The code segment is as below:</p>
  
  <pre><code>$professionals = DB::table('member_professional')
      -&gt;select("member_professional.*",
          DB::raw("(GROUP_CONCAT(DISTINCT photos.picture_path SEPARATOR ',')) as 'photos'"))
      -&gt;join('member','member_professional.member_id_fk','=','member.member_id')
      -&gt;join('photos','photos.member_fk','=','member.member_id')
      -&gt;leftjoin('locations','member.city','=','locations.location_id');
  
          if ($professionals_type != '') {
                       $professionals = $professionals-&gt;where('member_professional.biz_category','=',$professionals_type);
          }
  
          if ($location != '') {
                       $professionals = $professionals-&gt;where('member.city','=',$location);
          }
  
      $professionals = $professionals-&gt;where('member.member_type','=',2); 
      $professionals = $professionals-&gt;groupBy('member_professional.member_id_fk')
      -&gt;paginate(20);
  </code></pre>
  
  <p>When I run it on the staging server:  <a href="http://dev.interioradditions.pk/allProfessionals" rel="nofollow noreferrer">http://dev.interioradditions.pk/allProfessionals</a> it throws the error:</p>
  
  <blockquote>
    <p>SQLSTATE[42000]: Syntax error or access violation: 1055 'interior_dev_db.member_professional.biz_name' isn't in 
    GROUP BY (SQL: select <code>member_professional</code>.*, (GROUP_CONCAT(DISTINCT photos.picture_path SEPARATOR ',')) as 'photos' 
    from <code>member_professional</code> inner join <code>member</code> on <code>member_professional</code>.<code>member_id_fk</code> = <code>member</code>.<code>member_id</code> inner join <code>photos</code> on <code>photos</code>.<code>member_fk</code> = <code>member</code>.<code>member_id</code> 
    left join <code>locations</code> on <code>member</code>.<code>city</code> = <code>locations</code>.<code>location_id</code> 
    where <code>member</code>.<code>member_type</code> = 2 
    group by <code>member_professional</code>.<code>member_id_fk</code> limit 20 offset 0)</p>
  </blockquote>
  
  <p>Whereas when I extract the built sql query from the above statement and execute through PHPMyAdmin it runs fine and gives the result as expected. Please help on getting what's wrong in the Model query.</p>
  
  <p>Thanks!</p>