title: Automatically deleting NESTED related rows in Laravel 5.4 (Eloquent ORM)
body: <p>Let's assume I have a Book. This Book has Chapters and those Chapters in this Book have Subchapters. </p>
  
  <p>So I have three models: </p>
  
  <p>Book > Chapter > Subchapter</p>
  
  <p>When I delete the Book ($book->delete();), I also want to delete the related Chapters of this Book and also the related Subchapters of all the Chapters from the Book. </p>
  
  <p>Here (<a href="https://stackoverflow.com/questions/14174070/automatically-deleting-related-rows-in-laravel-eloquent-orm">Automatically deleting related rows in Laravel (Eloquent ORM)</a>) I found out about Eloquent Events. Whenever a Book is deleted, before that, the Chapter gets deleted because we hook in: </p>
  
  <pre><code>class Book extends Eloquent
  {
      public function chapters()
      {
          return $this-&gt;has_many('Chapter');
      }
  
      protected static function boot() {
          parent::boot();
  
          static::deleting(function($book) { 
               $book-&gt;chapters()-&gt;delete();
          });
      }
  }
  </code></pre>
  
  <p>So I thought, I only have to implement the same code in my Chapter-Model, only exchanging "Book" with "Chapter" and "Chapter" with "Subchapter": </p>
  
  <pre><code>class Chapter extends Eloquent
  {
      public function subChapters()
      {
          return $this-&gt;has_many('SubChapter');
      }
  
      protected static function boot() {
          parent::boot();
  
          static::deleting(function($chapter) { 
               $chapter-&gt;subChapters()-&gt;delete();
          });
      }
  }
  </code></pre>
  
  <p>This works fine when I delete a Chapter. All the Subchapters will also be deleted. </p>
  
  <p>When I delete the Book it works fine with the Chapters. All the Chapters will also be deleted. </p>
  
  <p>However it only deletes Chapters when I delete the Book. It does not delete the related Subchapters of the deleted Chapters. </p>
  
  <p>Can anybody help me?</p>