I am a noob and don’t have access right now to my coding person.
In the template/frontend it shows 3 pdf documents. I’d like to sort them to the most recent added (date).
I am able to change the sorting manual in the backend. I’d like to have control over the sorting, either following the manual sorting or sorting by the most recent date of the file.
I’d really appreciate if someone is able to help me
If there are no documents of that type, you will get a collection, albeit one that might be empty, but not two different type, like (empty) collection or false.
In your template, you can then check if there are any elements in the collection:
Where do you want to have control? Just do it in the template? Or do you want a button to change the sorting in the frontend? Or do you want to add a field in the Panel that lets you choose what sorting to use?
Good point. The sorting should be visible at the frontend, at the webpage. At the moment it is not changing at all, depeding on the sorting in the backend - where I actually can change the order -. It just shows the oldest entry always at first.
I’ll check on all your suggestions. The whole code is made very long time ago under v2 or so. Last year, the web site got upgraded to v4.1.0 and still is.
If you want to use the manual order from the Panel for your frontend as well you need to apply sorting by the sort field:
// sort by manual sort field
$files = $page->files()->sortBy('sort');
What would you like to do in the frontend? A toggle to change the sort direction? Different options to decide what to sort by (manual sort field, name, date,…)?