-<?php namespace BookStack\Entities\Models;
+<?php
+
+namespace BookStack\Entities\Models;
use BookStack\Uploads\Image;
-use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Bookshelf extends Entity implements HasCoverImage
{
+ use HasFactory;
+
protected $table = 'bookshelves';
- public $searchFactor = 3;
+ public $searchFactor = 1.2;
protected $fillable = ['name', 'description', 'image_id'];
/**
* Get the books in this shelf.
* Should not be used directly since does not take into account permissions.
+ *
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function books()
*/
public function visibleBooks(): BelongsToMany
{
- return $this->books()->visible();
- }
-
- /**
- * Get the books in this shelf that are visible to the current user with sorted by custom parameter
- * @param string $sort - Chosen Column to be sorted
- * @param string $order - Order of the sort
- * @return Collection
- */
- public function visibleBooksByCustomSorting(string $sort = 'name', string $order = 'asc'): Collection
- {
- return $this->belongsToMany(Book::class, 'bookshelves_books', 'bookshelf_id', 'book_id')
- ->orderBy($sort, $order)
- ->visible()
- ->get();
+ return $this->books()->scopes('visible');
}
/**
/**
* Returns BookShelf cover image, if cover does not exists return default cover image.
- * @param int $width - Width of the image
+ *
+ * @param int $width - Width of the image
* @param int $height - Height of the image
+ *
* @return string
*/
public function getBookCover($width = 440, $height = 250)
} catch (\Exception $err) {
$cover = $default;
}
+
return $cover;
}
/**
- * Get the cover image of the shelf
+ * Get the cover image of the shelf.
*/
public function cover(): BelongsTo
{
/**
* 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)