What you are doing is this
- Startdate Enddate
- 20230101 20230101
- 20230102 20230102
- 20230102 20230103
- 20230102 20230104
In which order do you want it to display?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all,
I am having a problem with an orderBy logic: Imagine you have events and they all have a starting date and an ending date.
When you show all your events in the front end, you may want to show in order, all the events close to start and started(starting_date) while having all the expired(ending_date) one at the back.
How would you do this please? I tried this:
Event::orderBy('starting_date', 'asc')->orderBy('ending_date', 'asc')->paginate(15);
But it is not giving me the right ordering.
Any idea how to achieve this please?
Thanks
@LaraBABA something like this:
Event::query()
->orderByRaw('ending_date < CURRENT_DATE()')
->orderBy('starting_date', 'asc')
->orderBy('ending_date', 'asc')
->paginate(15);
Please or to participate in this conversation.