ideas
ideas copied to clipboard
Taking the CP order into account when executing a querybuilder get(), for structured collections
Hi all,
I am executing the following query:
$this->getAugmentedValue(Collection::find('skills')->queryEntries()->where('status', 'published')->get())
In order to get the entries of the collection "skills". in fact, "skills" is a structured collection; i.e.: there is a tree file located under content/trees/collections/ directory that is associated to this collection. This tree by definition contains the collection's entries in the order defined by the drag'n drops the user performed in control panel in the tree listing of the entries.
However, the above line of code doesn't take into account this drag'n drop order.
My question is: could you please add a feature to take it into account? You could for example add a SQL numeric field "cpDragNDropOrder" , allowing us to do a orderBy('cpDragNDropOrder').
Thank you in advance. Best regards,
This is certainly not the best way to do it (I presume anyway, maybe someone else can confirm) but this should do the job if you need a workaround.
collect(\Statamic\Facades\Collection::find('skills')->structure()->in('default')->tree())
->map(function ($item) {
return \Statamic\Facades\Entry::find($item['entry']);
})
->filter(function ($entry) {
return $entry->published();
});