lundi 17 juillet 2017

Laravel 5.1 Fetch Rows between start_time and end_time (two different fields)

I've been working on reservation project, I collect request (time_start and time_end) and add 1:30 hour to each so i can prevent user to select conflicts.

I tried using "Between" already but it doesnt seems to work.

->whereBetween('reservation_time_start', [$time_from, $time_to])
->whereBetween('reservation_time_end', [$time_from, $time_to])

I also tried this,

->whereRaw('((reservation_time_end <= ? AND reservation_time_end >= ?) OR (reservation_time_start >= ? AND reservation_time_start <= ?))',[$time_end, $time_start,$time_start, $time_end])

It work but in some cases like between some time range, i dont get any results. Like This.

+----+------------------------+----------------------+
| id | reservation_time_start | reservation_time_end |
+----+------------------------+----------------------+
|  1 | 10:00:00               | 13:00:00             | <- i need to get this
|  2 | 12:00:00               | 14:00:00             |
|  3 | 14:00:00               | 15:00:00             |
+----+------------------------+----------------------+

sample user input's: $reservation_time_start = 12:00:00 (-1:30 Hour) $reservation_time_end = 14:00:00 (+ 1:30 hour)

and when i run my code, it returns null. Please help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire