X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/60d0f96cd754a85c637a5f34dcc0341f4ef72a46..refs/pull/1688/head:/app/Entities/Bookshelf.php diff --git a/app/Entities/Bookshelf.php b/app/Entities/Bookshelf.php index 745611ba7..7ad2415ed 100644 --- a/app/Entities/Bookshelf.php +++ b/app/Entities/Bookshelf.php @@ -104,4 +104,18 @@ class Bookshelf extends Entity { return $this->books()->where('id', '=', $book->id)->count() > 0; } + + /** + * Add a book to the end of this shelf. + * @param Book $book + */ + public function appendBook(Book $book) + { + if ($this->contains($book)) { + return; + } + + $maxOrder = $this->books()->max('order'); + $this->books()->attach($book->id, ['order' => $maxOrder + 1]); + } }