Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/InteractsWithMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,10 @@ private function getMediaItemUrl(string $collectionName, string $conversionName,
? $this->getFirstMedia($collectionName)
: $this->getLastMedia($collectionName);

if (! $media) {
if (! $media || ($conversionName !== '' && ! $media->hasGeneratedConversion($conversionName))) {
return $this->getFallbackMediaUrl($collectionName, $conversionName) ?: '';
}

if ($conversionName !== '' && ! $media->hasGeneratedConversion($conversionName)) {
return $media->getUrl();
}

return $media->getUrl($conversionName);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/InteractsWithMedia/GetMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
expect($this->testModelWithConversionQueued->getFirstMediaPath('avatar', 'avatar_thumb'))->toEqual($media->getPath('avatar_thumb'));
});

it('can get the default url to the first media in a collection if conversion not marked as generated yet', function () {
it('will return empty url when first media in a collection the conversion not marked as generated yet', function () {
$media = $this
->testModelWithConversionQueued
->addMedia($this->getTestJpg())
Expand All @@ -345,7 +345,7 @@
unlink($avatarThumbConversion);
$this->testModelWithConversionQueued->getFirstMedia('avatar')->markAsConversionNotGenerated('avatar_thumb');

expect($this->testModelWithConversionQueued->getFirstMediaUrl('avatar', 'avatar_thumb'))->toEqual("/media/{$media->id}/test.jpg");
expect($this->testModelWithConversionQueued->getFirstMediaUrl('avatar', 'avatar_thumb'))->toEqual('');
});

it('will return preloaded media sorting on order column', function () {
Expand Down
Loading