GROUP_CONCAT (CONCAT... in Laravel?

Asked

Viewed 54 times

1

I don’t know if anyone can help me I needed to execute this SQL in Laravel I just don’t know how to use the GROUP_CONCAT with the CONCAT within?

select dictionaries.name, 
GROUP_CONCAT(CONCAT('{name:"', dictionary_files.name, '", file:"',dictionary_files.path,'"}')) as files
from dictionaries  
join dictionary_files on dictionaries.`id` = dictionary_files.`dictionary_id`
Where dictionary_files.name Like "Teste%" Group by dictionaries.name

Thank you.

1 answer

1


Basically with Query Builder:

$dictionaries = DB::table('dictionaries')
  ->select(DB::raw('dictionaries.name, GROUP_CONCAT(CONCAT("{name:",dictionary_files.name,"file:",dictionary_files.path,"}")) as files'))
  ->where('dictionary_files.name', 'LIKE', "Teste%")
  ->groupBy('dictionaries.name')
  ->get();

Observing: had also concatenção wrong, quotes out of place, but, with Query Builder will solve your problem.

References

Browser other questions tagged

You are not signed in. Login or sign up in order to post.