John Davidson

mysql - Query single column and return comma separated Laravel PHP

0 comments
Message:


 $getStrain = DB::connection('mysql')->select('
SELECT

b.yeast_class_id
FROM
yeast_classes AS a
LEFT JOIN
classes_per_yeast AS b
ON
a.id = b.yeast_class_id
WHERE
b.yeast_id = "'.$id.'"
GROUP BY
b.yeast_class_id
');

dd($getStrain);

and it returns something like this



But what I want to do is get a response something like this


1,4,5,6,7


where all yeast_class_id will be combined together



My Answer:
>select('strain_name')
->from('strains')
->pluck('strain_name')
->implode(', ');

Rate this post

4 of 5 based on 4433 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us