Back

pass a mysql query to a laravel query builder


MonoDev posted 1 week ago

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?

joedixon replied 1 week ago

Hi @MonoDev,

It's hard to give you the full answer without seeing the full query, but you could use DB::raw('your custom query here') as part of the query builder.

Hope this helps!


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us