X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/8e78b4c43eb980f47d9c207a0ce3330699d54103..refs/pull/5591/head:/app/Entities/Queries/BookshelfQueries.php diff --git a/app/Entities/Queries/BookshelfQueries.php b/app/Entities/Queries/BookshelfQueries.php index 52e123087..19717fb7c 100644 --- a/app/Entities/Queries/BookshelfQueries.php +++ b/app/Entities/Queries/BookshelfQueries.php @@ -8,6 +8,11 @@ use Illuminate\Database\Eloquent\Builder; 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(); @@ -18,7 +23,18 @@ class BookshelfQueries implements ProvidesEntityQueries return $this->start()->scopes('visible')->find($id); } - public function findVisibleBySlug(string $slug): Bookshelf + 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() @@ -35,7 +51,7 @@ class BookshelfQueries implements ProvidesEntityQueries public function visibleForList(): Builder { - return $this->start()->scopes('visible'); + return $this->start()->scopes('visible')->select(static::$listAttributes); } public function visibleForListWithCover(): Builder