-
My understanding is that getFirstMedia will return the first item in the Media Collection, but I assume this is not always the latest item added to that collection. Is the filter variable documented anywhere? Or is there an out of the box function to get the latest uploaded file to a given collection? |
Beta Was this translation helpful? Give feedback.
Answered by
erikn69
Apr 2, 2022
Replies: 1 comment 1 reply
-
laravel-medialibrary/src/InteractsWithMedia.php Lines 279 to 284 in 92bc4b2 Make your own trait, with your own logic public function getLastMedia(string $collectionName = 'default', $filters = []): ?Media
{
$media = $this->getMedia($collectionName, $filters);
return $media->last();
}
public function getLatestMedia(string $collectionName = 'default', $filters = []): ?Media
{
$media = $this->getMedia($collectionName, $filters);
return $media->sortBy('created_at')->values()->last();
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
MCKLtech
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
laravel-medialibrary/src/InteractsWithMedia.php
Lines 279 to 284 in 92bc4b2
Make your own trait, with your own logic