use BookStack\Exceptions\NotFoundException;
use Illuminate\Database\Eloquent\Builder;
-class BookshelfQueries
+class BookshelfQueries implements ProvidesEntityQueries
{
+ protected static array $listAttributes = [
+ 'id', 'slug', 'name', 'description',
+ 'created_at', 'updated_at', 'image_id', 'owned_by',
+ ];
+
public function start(): Builder
{
return Bookshelf::query();
}
- public function findVisibleBySlug(string $slug): Bookshelf
+ public function findVisibleById(int $id): ?Bookshelf
+ {
+ return $this->start()->scopes('visible')->find($id);
+ }
+
+ public function findVisibleByIdOrFail(int $id): Bookshelf
+ {
+ $shelf = $this->findVisibleById($id);
+
+ if (is_null($shelf)) {
+ throw new NotFoundException(trans('errors.bookshelf_not_found'));
+ }
+
+ return $shelf;
+ }
+
+ public function findVisibleBySlugOrFail(string $slug): Bookshelf
{
/** @var ?Bookshelf $shelf */
$shelf = $this->start()
public function visibleForList(): Builder
{
- return $this->start()->scopes('visible');
+ return $this->start()->scopes('visible')->select(static::$listAttributes);
}
public function visibleForListWithCover(): Builder