Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MonoDev's avatar

pass a mysql query to a laravel query builder

I have a slightly complex query that I first made in flat mysql, but I don't know how to translate a part of it in the query builder of Laravel, the part I would like to pass is this:

FROM
(
    SELECT 1 AS month UNION ALL
    SELECT 2 UNION ALL
    SELECT 3 UNION ALL
    SELECT 4 UNION ALL
    SELECT 5 UNION ALL
    SELECT 6 UNION ALL
    SELECT 7 UNION ALL
    SELECT 8 UNION ALL
    SELECT 9 UNION ALL
    SELECT 10 UNION ALL
    SELECT 11 UNION ALL
    SELECT 12
) t1

Any idea how I can do this?

0 likes
3 replies
jlrdw's avatar

Yes, Use as is with db facade. Bind any parameters.

Please or to participate in this conversation.