Eloquent is reallt good and very powerful but sometimes its just better to write the query yourself.
With that in mind I'd look into using DB::raw()
Check out the documentation https://laravel.com/docs/4.2/queries#unions
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I would like to know how to write this query in Laravel.
SELECT * FROM ( SELECT ce.empresa_id, CONCAT(ce.nombre, ' ', ce.apellido) AS nombre, ce.grupo_contable FROM cliente_empresa AS ce UNION SELECT cc.empresa_id, cc.nombre, cc.grupo_contable FROM cuenta_contable AS cc UNION SELECT cci.empresa_id, cci.grupo_iva AS nombre, cci.cuenta_contable AS grupo_contable FROM cuenta_contables_iva AS cci ) AS cuentasContables WHERE cuentasContables.empresa_id = 1 AND (cuentasContables.nombre LIKE '%a%' OR cuentasContables.grupo_contable LIKE '%100%')
I'm new to Laravel so I don't know much about Database Queries and when looking at Documentation i can't find 'UNIONS' and things like that.
Thank you.
Please or to participate in this conversation.