Skip to content

Commit

Permalink
fix bugs regarding attaching media to non-existing models
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed May 23, 2017
1 parent dc515cf commit 22fd808
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@ All notable changes to `laravel-medialibrary` will be documented in this file

## 5.11.1 - 2017-05-23

- fix bugs regarding attaching media to non-existing models

## 5.11.0 - 2017-05-10

Expand Down
4 changes: 3 additions & 1 deletion src/HasMedia/HasMediaTrait.php
Expand Up @@ -414,7 +414,9 @@ protected function mediaIsPreloaded(): bool
*/
public function loadMedia(string $collectionName)
{
$collection = $this->exists ? $this->media : collect($this->unsavedMediaItems);
$collection = $this->exists
? $this->media
: collect($this->unAttachedMediaLibraryItems)->pluck('media');

return $collection
->filter(function (Media $mediaItem) use ($collectionName) {
Expand Down

0 comments on commit 22fd808

Please sign in to comment.