I have this situation I have a files collection and I want to inject a file at a specific position set by the user in the panel.
The use case is a slideshow with images and videos picked from project pages via the files picker and another field to add a special holiday info slide into the set. What I came up with is this:
$media = $page->slideshow()->toFiles();
if($eventMedia = $page->event_media()->toFile()){
array_splice($media->data, $page->event_media_position()->int() - 1, 0, [$eventMedia]);
}
I didn’t find a built in collection method for this and I was wondering if there is one.