how to use GROUP_CONCAT in laravel -


$assignment = assignment::find(crypt::decrypt($id)); $assignment_details = $assignment->raw_plan()->groupby('flag')->get(); 

i want following result of query in laravel

select group_concat(name) 'names' `raw_plans` `assignment_id` = 1 group by`flag` 

please suggest me how use group_concat in laravel

you can use relations query builder fetch results as:

$assignment_details = $assignment->raw_plan()                                 ->select(db::raw('group_concat(name) names'))                                 ->where('assignment_id', 1)                                 ->groupby('flag')                                 ->get(); 

update

use table_name.* in select fields.

$assignment_details = $assignment->raw_plan()                                 ->select('raw_plans.*', db::raw('group_concat(name) names'))                                 ->where('assignment_id', 1)                                 ->groupby('flag')                                 ->get(); 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

Laravel mail error `Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]` -

c# SetCompatibleTextRenderingDefault must be called before the first -