- if ($entity instanceof Page) {
- return $this->destroyPage($entity);
- }
- if ($entity instanceof Chapter) {
- return $this->destroyChapter($entity);
- }
- if ($entity instanceof Book) {
- return $this->destroyBook($entity);
- }
- if ($entity instanceof Bookshelf) {
- return $this->destroyShelf($entity);
- }
+ $result = (new DatabaseTransaction(function () use ($entity) {
+ if ($entity instanceof Page) {
+ return $this->destroyPage($entity);
+ } else if ($entity instanceof Chapter) {
+ return $this->destroyChapter($entity);
+ } else if ($entity instanceof Book) {
+ return $this->destroyBook($entity);
+ } else if ($entity instanceof Bookshelf) {
+ return $this->destroyShelf($entity);
+ }
+ return null;
+ }))->run();