Jag har överlappande borttagningar som fungerar med modellhändelser , till exempel i en produktmodell binder jag till den borttagna händelsen så att jag kan mjukradera alla relationer:
// Laravel's equivalent to calling the constructor on a model
public static function boot()
{
// make the parent (Eloquent) boot method run
parent::boot();
// cause a soft delete of a product to cascade to children so they are also soft deleted
static::deleted(function($product)
{
$product->images()->delete();
$product->descriptions()->delete();
foreach($product->variants as $variant)
{
$variant->options()->delete();
$variant->delete();
}
});
}