I’m trying to shuffle through a list. While it’s working nicely, I’m wondering if that is possible to shuffle the whole list except the first element of that list.
<?php foreach ($site->children()->filterBy('template', 'doing')->offset(1)->shuffle() as $doing) : ?>
$children = $site->children()->filterBy('template', 'doing')->offset(1)->shuffle(); // Assuming toArray() converts it to an array
$firstElement = $site->children()->filterBy('template', 'doing')->first(); // Remove and store the first element
I thought about merging these two queries, but I’m not sure on how to do it… Is it the correct idea?
Yeah, this is working, but what I wanted was to keep the first element in that list always the first element. Here it’s only showing me the list as if I was doing an ->offset(1)…
Yes, the code didn’t make any changes. If you want the first item inside the collection again, you would have to prepend it in order to loop through all, rather than rendering the first and then the rest: