Skip to content

Commit 650d8a5

Browse files
committed
fix fallback as static method
1 parent f37f155 commit 650d8a5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

config/titelive-client.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
],
1717
],
1818
],
19-
'book_visual_placeholder_url' => asset('/img/book-placeholder.png'),
2019
];

src/Book.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Book extends Model implements JsonSerializable
2222
'availability' => BookAvailability::class,
2323
];
2424

25+
protected static ?string $fallbackVisualUrl = null;
26+
2527
protected static function newFactory()
2628
{
2729
return new BookFactory;
@@ -64,17 +66,22 @@ public function canBeOrdered(): bool
6466
&& ($this->hasStock() || $this->availability == BookAvailability::AvailableOnDemand);
6567
}
6668

67-
public function visual(string $size, ?string $placeholder = null): ?string
69+
public function visual(string $size, ?string $fallbackUrl = null): ?string
6870
{
6971
$url = $this->visuals[$size] ?? null;
7072

7173
if (preg_match('/no_image\.png/', $url)) {
72-
return $placeholder ?? config('titelive-client.book_visual_placeholder_url');
74+
return $fallbackUrl ?: static::$fallbackVisualUrl ?: asset('/img/book-placeholder.png');
7375
}
7476

7577
return $url;
7678
}
7779

80+
public static function setFallbackVisualUrl(string $url): void
81+
{
82+
static::$fallbackVisualUrl = $url;
83+
}
84+
7885
public function jsonSerialize(): array
7986
{
8087
return (new BookJsonResource($this))->jsonSerialize();

0 commit comments

Comments
 (0)