I am making a schedule display system and it shows the schedules of ferries. my problem is if I dont put midnight time in order then query skips midnight time and displays morning instead
EXAMPLE:-
if i put data in order like this
- 1:30 am
- 6:30 am
- 7:30 am
then the times show correctly, but if its not in order
- 6:30 am
- 7:30 am
- 1:30 am
then the query skips the 1:30 am and goes straight to 6:30 to display.
Here is my laravel SQL Query:- if departure time is greater than current time then show the next available one
DB::table('ferries')->groupBy('ferry_name')
->whereTime('departure_time', '>', Carbon::now()->toTimeString())
->whereIn('schedule_type', ['Weekday'])
->where('terminal_name', $terminal_name)->get()->all();
My Answer:
>where('departure_time', '>', Carbon::now())
>orderBy('departure_time')
>first();
Rate this post
4 of 5 based on 8507 votesComments