I have a list of events.
These events have status updates.
I'm paginating the statuses 10 per page.
When the page is loaded the status updates are ordered by created_at desc.
I also have links to order by ascending or descending by passing ?sort=asc or ?sort=desc in the URL.
$sort = $request->has('sort') ? $request->query('sort') : 'desc';
if($sort == 'asc') {
$statuses = $event->statuses()->oldest()->paginate(10);
} else {
$statuses = $event->statuses()->latest()->paginate(10);
}
When an event has finished, it is marked as completed. Then the event is ordered by created_at desc. So that it reads from the beginning, like so:
if($sort == 'asc' || $event->completed) {
$statuses = $event->statuses()->oldest()->paginate(10);
} else {
$statuses = $event->statuses()->latest()->paginate(10);
}
However, if you then try and sort a completed event by statuses created_at DESC` it sees that the event is completed and orders by ASC.
if($sort == 'asc' || `$event->completed`) {
$statuses = $event->statuses()->oldest()->paginate(10);
} else {
$statuses = $event->statuses()->latest()->paginate(10);
}
How do I adjust it so that you can sort a completed event by statuses DESC?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community