Skip to content

Commit c292da4

Browse files
committed
Fix availability WTF
1 parent 36deb1d commit c292da4

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Book.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ public function canBeOrdered(): bool
6464
&& ($this->hasStock() || $this->availability == BookAvailability::AvailableOnDemand);
6565
}
6666

67-
public function getAvailabilityLabelAttribute(): ?string
67+
public function availabilityLabel(): Attribute
6868
{
69-
return $this->hasStock() && $this->availability != BookAvailability::Forthcoming
70-
? null
71-
: $this->availability->getLabel();
69+
return Attribute::make(
70+
get: fn () => $this->hasStock() && $this->availability != BookAvailability::Forthcoming
71+
? null
72+
: $this->availability->getLabel()
73+
);
7274
}
7375

7476
public function visual(string $size): string
@@ -82,6 +84,15 @@ public function visual(string $size): string
8284
return $url;
8385
}
8486

87+
public function jsonSerialize(): array
88+
{
89+
return [
90+
...$this->toArray(),
91+
'availability_label' => $this->availability_label,
92+
'url' => $this->url,
93+
];
94+
}
95+
8596
public function resolveRouteBinding($value, $field = null)
8697
{
8798
if (is_array($value)) {

0 commit comments

Comments
 (0)