Exemple #1
0
 public static function boot()
 {
     parent::boot();
     // Attach event handler for deleting a section
     Section::deleting(function ($section) {
         /*
                     to keep a cascading delete when using softDeletes we must remove the related models here
         */
         $children = ['sections', 'topics'];
         Log::info("Deleting Section {$section->title} - {$section->id}");
         foreach ($children as $child) {
             if ($section->{$child}()) {
                 Log::info(" - removing section->{$child}");
                 // we need to call delete on the grandchilden to
                 // trigger their delete() events - seems dumb
                 foreach ($section->{$child} as $grandchild) {
                     $grandchild->delete();
                 }
             }
         }
     });
 }