protected $table = 'bookshelves';
- public $searchFactor = 3;
+ public $searchFactor = 1.2;
protected $fillable = ['name', 'description', 'image_id'];
- protected $hidden = ['restricted', 'image_id', 'deleted_at'];
+ protected $hidden = ['image_id', 'deleted_at'];
/**
* Get the books in this shelf.
*/
public function visibleBooks(): BelongsToMany
{
- return $this->books()->visible();
+ return $this->books()->scopes('visible');
}
/**
*/
public function coverImageTypeKey(): string
{
- return 'cover_shelf';
+ return 'cover_bookshelf';
}
/**
* Check if this shelf contains the given book.
- *
- * @param Book $book
- *
- * @return bool
*/
public function contains(Book $book): bool
{
/**
* Add a book to the end of this shelf.
- *
- * @param Book $book
*/
public function appendBook(Book $book)
{
$maxOrder = $this->books()->max('order');
$this->books()->attach($book->id, ['order' => $maxOrder + 1]);
}
+
+ /**
+ * Get a visible shelf by its slug.
+ * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
+ */
+ public static function getBySlug(string $slug): self
+ {
+ return static::visible()->where('slug', '=', $slug)->firstOrFail();
+ }
}