如何在laravel中将mysql转换为查询生成器

时间:2018-05-29 07:39:46

标签: mysql laravel

我在MySQL中有这个原始查询我需要翻译成laravel 5.5查询构建器。感谢

SELECT
group_table.id,
group_table.name,
group_table.description,
GROUP_CONCAT(
    group_table.languageName SEPARATOR ', '
) as languages
FROM
(
    SELECT
        translate_groups.id,
        translate_groups.name,
        translate_groups.description,
        languages.name as languageName
    FROM
        translate_groups
    LEFT JOIN language_translate_group ON
        language_translate_group.translate_group_id = translate_groups.id
    LEFT JOIN languages ON
        language_translate_group.language_id = languages.id
) group_table
GROUP BY
group_table.id,
group_table.name,
group_table.description

1 个答案:

答案 0 :(得分:0)

您可以在查询构建器中运行所需的任何原始查询:

$queryString = 'WHAT RAW QUERY YOU WANT';
$result = DB::select(DB::raw($queryString));

只需使用Illuminate\Support\Facades\DB;