X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/8d7febe482f92a34093127c60c6e2dda342b4223..refs/pull/4467/head:/app/Entities/Models/Book.php diff --git a/app/Entities/Models/Book.php b/app/Entities/Models/Book.php index 8217d2cab..fc4556857 100644 --- a/app/Entities/Models/Book.php +++ b/app/Entities/Models/Book.php @@ -19,6 +19,7 @@ use Illuminate\Support\Collection; * @property \Illuminate\Database\Eloquent\Collection $chapters * @property \Illuminate\Database\Eloquent\Collection $pages * @property \Illuminate\Database\Eloquent\Collection $directPages + * @property \Illuminate\Database\Eloquent\Collection $shelves */ class Book extends Entity implements HasCoverImage { @@ -27,7 +28,7 @@ class Book extends Entity implements HasCoverImage public $searchFactor = 1.2; protected $fillable = ['name', 'description']; - protected $hidden = ['restricted', 'pivot', 'image_id', 'deleted_at']; + protected $hidden = ['pivot', 'image_id', 'deleted_at']; /** * Get the url for this book. @@ -119,4 +120,13 @@ class Book extends Entity implements HasCoverImage return $pages->concat($chapters)->sortBy('priority')->sortByDesc('draft'); } + + /** + * Get a visible book by its slug. + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException + */ + public static function getBySlug(string $slug): self + { + return static::visible()->where('slug', '=', $slug)->firstOrFail(); + } }