3 namespace BookStack\Entities\Queries;
5 use BookStack\Entities\Models\Bookshelf;
6 use BookStack\Exceptions\NotFoundException;
7 use Illuminate\Database\Eloquent\Builder;
11 public function start(): Builder
13 return Bookshelf::query();
16 public function findVisibleBySlug(string $slug): Bookshelf
18 /** @var ?Bookshelf $shelf */
19 $shelf = $this->start()
21 ->where('slug', '=', $slug)
24 if ($shelf === null) {
25 throw new NotFoundException(trans('errors.bookshelf_not_found'));
31 public function visibleForList(): Builder
33 return $this->start()->scopes('visible');
36 public function visibleForListWithCover(): Builder
38 return $this->visibleForList()->with('cover');
41 public function recentlyViewedForCurrentUser(): Builder
43 return $this->visibleForList()
44 ->scopes('withLastView')
45 ->having('last_viewed_at', '>', 0)
46 ->orderBy('last_viewed_at', 'desc');
49 public function popularForList(): Builder
51 return $this->visibleForList()
52 ->scopes('withViewCount')
53 ->having('view_count', '>', 0)
54 ->orderBy('view_count', 'desc');