]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Queries/BookshelfQueries.php
Layout: Converted tri-layout component to ts
[bookstack] / app / Entities / Queries / BookshelfQueries.php
index d61607e7a5a9b0d24c830b61b79b301273303d09..19717fb7cd4daf0bd8b3fd1d530dc6ffe239b49c 100644 (file)
@@ -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,6 +23,17 @@ class BookshelfQueries implements ProvidesEntityQueries
         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 */
@@ -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