Skip to content

Commit

Permalink
support parameters in hasMedia
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Sep 28, 2024
1 parent 2eacfa0 commit f2b8613
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Traits/HasMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,31 @@ public function hasMedia(?string $collection_name = null, ?string $collection_gr
/**
* @return TMedia
*/
public function getFirstMedia(?string $collection_name = null, ?string $collection_group = null)
{
public function getFirstMedia(
?string $collection_name = null,
?string $collection_group = null
) {
return $this->getMedia($collection_name, $collection_group)->first();
}

/**
* @param null|bool|string|array<int, string> $fallback
*/
public function getFirstMediaUrl(
?string $collection_name = null,
?string $collection_group = null,
?string $conversion = null,
null|bool|string|array $fallback = null,
?array $parameters = null,
): ?string {
$media = $this->getFirstMedia($collection_name, $collection_group);

if ($media) {
return $media->getUrl($conversion);
return $media->getUrl(
conversion: $conversion,
fallback: $fallback,
parameters: $parameters
);
}

$collection = $this->getMediaCollection($collection_name);
Expand Down

0 comments on commit f2b8613

Please sign in to comment.