Aquí está mi código:
$arr = Event::select('user_id', 'start', 'end') ->where('start', '!=', $from) ->whereBetween('start', [$from, $till]) ->orWhere(function($query) use ($from, $till) { $query->where('end', '!=', $till) ->whereBetween('end', [$from, $till]); })->get();valor inicial: 2021-07-11 9:00:00 valor final: 2021-07-11 15:00:00
$desde valor: 2021-07-11 10:30:00 $hasta valor: 2021-07-11 13:00:00
También probé con Carbon, pero el resultado de la consulta no es nada. ¿Cuál es el problema? También probé con:
$arr = Event::where('start', '>', $from) ->where('start', '<', $till) ->get();¡Simplemente no funciona!
El segmento de código principal tiene algún pequeño defecto con
where between('inicio', [$desde, $hasta])
Porque su fecha de inicio no se encuentra entre su valor desde y hasta. Eso no devuelve nada en realidad.
Prueba con tu segunda solución. Con un pequeño cambio en él.
$arr = Event::where('start', '<=', $from) ->where('end', '>=', $till) ->get();