/** * The "booting" method of the model. * * @return void */ protected static function boot() { parent::boot(); static::deleting(function (self $attachment) { File::delete($attachment->getPath()); }); }
/** * The "booting" method of the model. * * @return void */ protected static function boot() { parent::boot(); static::deleting(function (self $document) { $document->load(['attachments'])->getRelation('attachments')->each(function (Attachment $attachment) { $attachment->delete(); }); }); }