Skip to content

Commit

Permalink
Update SpatieMediaLibraryFileUpload.php
Browse files Browse the repository at this point in the history
Allow to define a conversion of image to be displayed
  • Loading branch information
martin-ro authored Feb 18, 2022
1 parent 6d99934 commit 38c5297
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class SpatieMediaLibraryFileUpload extends FileUpload
{
protected string | Closure | null $collection = null;

protected string | Closure | null $conversion = null;

protected string | Closure | null $mediaName = null;

protected function setUp(): void
Expand Down Expand Up @@ -68,6 +70,10 @@ protected function setUp(): void
return $media?->getTemporaryUrl(now()->addMinutes(5));
}

if ($component->getConversion() && $media->hasGeneratedConversion($component->getConversion())) {
return $media?->getUrl($component->getConversion());
}

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

Expand Down Expand Up @@ -125,6 +131,18 @@ public function getCollection(): string
return $this->evaluate($this->collection) ?? 'default';
}

public function conversion(string | Closure | null $conversion): static
{
$this->conversion = $conversion;

return $this;
}

public function getConversion(): string
{
return $this->evaluate($this->conversion) ?? '';
}

public function mediaName(string | Closure | null $name): static
{
$this->mediaName = $name;
Expand Down

0 comments on commit 38c5297

Please sign in to comment.