vendredi 27 janvier 2017

Delete Laravel 5.3 polymorphic items when deleting parent via cascade

I'm trying to delete polymorphic items/relationships when a parent is deleted.

My structure is;

- User (hasMany: Page)
- - Page (hasMany: PageContent, belongsTo: User)
- - - PageContent (belongsTo: Page, hasMany: Module)
- - - - - Module (belongsTo: PageContent, morphTo: content())
- - - - - - ModuleVideo (morphMany: 'content')
- - - - - - ModuleAudio (morphMany: 'content')
- - - - - - ModuleSomething (morphMany: 'content')

I can delete the Module and ModuleItem by pinging Module directly;

$module->forceDelete();
$module->content->forceDelete();

The User > Page > PageContent > Module are all setup so onDelete they cascade down. I'm trying to force ModuleItem to delete if any of the parents (grandparents, etc.) are deleted?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire