Skip to content

Commit 9e6260b

Browse files
committed
update asset service
1 parent ae11d33 commit 9e6260b

4 files changed

Lines changed: 6 additions & 17 deletions

File tree

src/Dtos/SeoDto.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function __toString(): string
285285
$html .= "<meta property=\"og:description\" content=\"{$this->ogDescription}\">\n";
286286
}
287287

288-
if ($this->ogImage && ($mediaAssetUrl = inspirecms_asset()->findByKey($this->ogImage)?->getUrl())) {
288+
if ($this->ogImage && ($mediaAssetUrl = inspirecms_asset()->findByKeys($this->ogImage)->first()?->getUrl())) {
289289
$html .= "<meta property=\"og:image\" content=\"{$mediaAssetUrl}\">\n";
290290
}
291291

src/Http/Controllers/AssetController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function __construct(AssetService $assetService)
1616

1717
public function __invoke($key)
1818
{
19-
$asset = $this->assetService->findByKey($key);
19+
$asset = $this->assetService->findByKeys($key)->first();
2020

2121
$media = $asset?->getFirstMedia();
2222

src/Services/AssetService.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@
99
class AssetService implements AssetServiceInterface
1010
{
1111
/** {@inheritDoc} */
12-
public function findByKey(string | int $key)
12+
public function findByKeys($keys)
1313
{
14-
return $this->getQuery()->with('media')->find($key);
15-
}
16-
17-
/** {@inheritDoc} */
18-
public function findByKeys(...$keys)
19-
{
20-
$keys = array_filter(Arr::flatten($keys));
14+
$keys = array_filter(is_string($keys) ? [$keys] : Arr::flatten($keys));
2115

2216
if (count($keys) === 0) {
2317
return collect();

src/Services/AssetServiceInterface.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@
1010
interface AssetServiceInterface
1111
{
1212
/**
13-
* @return ?TResult
14-
*/
15-
public function findByKey(string | int $key);
16-
17-
/**
18-
* @param string|int ...$keys
13+
* @param string|string[] $keys
1914
* @return Collection<TResult>
2015
*/
21-
public function findByKeys(...$keys);
16+
public function findByKeys($keys);
2217
}

0 commit comments

Comments
 (0)