public function getUrl($path = false)
{
if ($path !== false) {
- return baseUrl('/shelves/' . urlencode($this->slug) . '/' . trim($path, '/'));
+ return url('/shelves/' . urlencode($this->slug) . '/' . trim($path, '/'));
}
- return baseUrl('/shelves/' . urlencode($this->slug));
+ return url('/shelves/' . urlencode($this->slug));
}
/**
}
try {
- $cover = $this->cover ? baseUrl($this->cover->getThumb($width, $height, false)) : $default;
+ $cover = $this->cover ? url($this->cover->getThumb($width, $height, false)) : $default;
} catch (\Exception $err) {
$cover = $default;
}
public function getExcerpt(int $length = 100)
{
$description = $this->description;
- return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
+ return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description;
}
/**
* @param Book $book
* @return bool
*/
- public function contains(Book $book)
+ public function contains(Book $book): bool
{
return $this->books()->where('id', '=', $book->id)->count() > 0;
}
+
+ /**
+ * Add a book to the end of this shelf.
+ * @param Book $book
+ */
+ public function appendBook(Book $book)
+ {
+ if ($this->contains($book)) {
+ return;
+ }
+
+ $maxOrder = $this->books()->max('order');
+ $this->books()->attach($book->id, ['order' => $maxOrder + 1]);
+ }
}