]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Queries/ChapterQueries.php
Layout: Converted tri-layout component to ts
[bookstack] / app / Entities / Queries / ChapterQueries.php
index 200514932cd186cd470bf11a47941d8fe925c0a9..53c5bc9d8423a7fe380d7eb67bd2cd9ab27ab040 100644 (file)
@@ -10,8 +10,7 @@ class ChapterQueries implements ProvidesEntityQueries
 {
     protected static array $listAttributes = [
         'id', 'slug', 'name', 'description', 'priority',
-        'created_at', 'updated_at',
-        'created_by', 'updated_by', 'owned_by',
+        'book_id', 'created_at', 'updated_at', 'owned_by',
     ];
 
     public function start(): Builder
@@ -24,10 +23,17 @@ class ChapterQueries implements ProvidesEntityQueries
         return $this->start()->scopes('visible')->find($id);
     }
 
+    public function findVisibleByIdOrFail(int $id): Chapter
+    {
+        return $this->start()->scopes('visible')->findOrFail($id);
+    }
+
     public function findVisibleBySlugsOrFail(string $bookSlug, string $chapterSlug): Chapter
     {
         /** @var ?Chapter $chapter */
-        $chapter = $this->start()->with('book')
+        $chapter = $this->start()
+            ->scopes('visible')
+            ->with('book')
             ->whereHas('book', function (Builder $query) use ($bookSlug) {
                 $query->where('slug', '=', $bookSlug);
             })
@@ -41,9 +47,19 @@ class ChapterQueries implements ProvidesEntityQueries
         return $chapter;
     }
 
+    public function usingSlugs(string $bookSlug, string $chapterSlug): Builder
+    {
+        return $this->start()
+            ->where('slug', '=', $chapterSlug)
+            ->whereHas('book', function (Builder $query) use ($bookSlug) {
+                $query->where('slug', '=', $bookSlug);
+            });
+    }
+
     public function visibleForList(): Builder
     {
         return $this->start()
+            ->scopes('visible')
             ->select(array_merge(static::$listAttributes, ['book_slug' => function ($builder) {
                 $builder->select('slug')
                     ->from('books')