Skip to content

Commit

Permalink
automatically set model relationship on media (#3319)
Browse files Browse the repository at this point in the history
Co-authored-by: michaelbaril <michaelbaril@users.noreply.github.com>
  • Loading branch information
michaelbaril and michaelbaril committed Jul 24, 2023
1 parent 3b52eff commit 8a00a55
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/InteractsWithMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,11 @@ public function loadMedia(string $collectionName): Collection

$collection = new MediaCollections\Models\Collections\MediaCollection($collection);

$modelWithoutMedia = (clone $this)->unsetRelation('media');

return $collection
->filter(fn (Media $mediaItem) => $collectionName !== '*' ? $mediaItem->collection_name === $collectionName : true)
->each(fn (Media $mediaItem) => $mediaItem->setRelation('model', $modelWithoutMedia))
->sortBy('order_column')
->values();
}
Expand Down

0 comments on commit 8a00a55

Please sign in to comment.