Skip to content

Commit

Permalink
Merge pull request #1654 from martin-ro/patch-7
Browse files Browse the repository at this point in the history
Update SpatieMediaLibraryFileUpload.php
  • Loading branch information
danharrin authored Feb 24, 2022
2 parents c115eab + e124947 commit 93cd948
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 @@ -120,11 +126,23 @@ public function collection(string | Closure | null $collection): static
return $this;
}

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

return $this;
}

public function getCollection(): string
{
return $this->evaluate($this->collection) ?? 'default';
}

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 93cd948

Please sign in to comment.