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
then the times show correctly, but if its not in order
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();
Resukltsets are by nature unsorted yo you need to add a sorting order
This would sort ascending see manual
DB::table('ferries')->groupBy('ferry_name')
->whereTime('departure_time', '>', Carbon::now()->toTimeString())
->whereIn('schedule_type', ['Weekday'])
->where('terminal_name',$terminal_name)->orderBy('departure_time')->get()->all()