I have a table sales_orders in this table I have 3 important fields:
- housing(numeric)
- status(enum)
- shipping_status(enum)
I need to make a query that filters me by the state when it is active and that the housing field is different from zero, but that null
returns them, that is, to clarify a bit the query would be something like this:
$venta=venta_pedidos::where('estado','aceptado')->where('vivenda','!=',0)->where('estado_envio','pendiente')->get();
But with this it does not return the ones null
from the housing field and if I enter the function it orWhereNull()
uses all of them null
without exception, it does not look at the state they are in.
In housing you have to indicate the field you want it to look at in this case housing:
I have tried that yesterday in a project and it has worked, that should help you.
Take a look at laravel advanced queries.
I have it solved:
It was nonsense, it turns out that I wasn't taking into account that if you put the orWhere() clause you have to specify the restrictive conditions again, so repeating the states again and updating the clause would do the trick, it would stay like this:
I think something like this could work for you:
If I'm not mistaken this will generate one
SQL
similar to this:Taking all those that have status = accepted, status_envio = pending and housing different from 0 or that is NULL