I'm trying this way:
Turnos::whereBetween(DB::raw("'".$req->crear_hora_inicial2."'"), ['hora_inicio','hora_final'])
->orWhereBetween(DB::raw("'".$req->crear_hora_final2."'"), ['hora_inicio', 'hora_final'])
->exists()
This creates the following sql:
select
exists(
select
*
from
"turnos"
where
'03:00' between 'hora_inicio' and 'hora_final'
or
'06:59' between 'hora_inicio' and 'hora_final'
)
as "exists"
The problem is that the columns that are hora_inicio
and hora_final
should tener doble comilla (")
, with comilla simple
the data base interprets it as a string
and I require that I recognize it as a column, as I already said double quotes.
Update 1:
I could not find a solution, I did this provisionally:
DB::select( DB::raw("select exists(select * from turnos where '$inicio' between hora_inicio and hora_final or '$fin' between hora_inicio and hora_final) as exists") );
The result (by Debugbar) is as follows:
array:1 [
0 => {#641
+"exists": false
}
]
How could I get only the boolean of exists
?