Skip to content

Commit

Permalink
Cleanup after model is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Apr 25, 2024
1 parent 86e8ed7 commit e14956d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion behaviors/TranslatableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,20 @@ public function __construct($model)

$model->morphMany['translations'] = [
'Winter\Translate\Models\Attribute',
'name' => 'model'
'name' => 'model',
'delete' => true,
];

$this->model->bindEvent('model.afterDelete', [$this, 'afterModelDelete']);
}

public function afterModelDelete()
{
// delete translation indexes for this record
Db::table('winter_translate_indexes')
->where('model_id', $this->model->getKey())
->where('model_type', $this->getClass())
->delete();
}

/**
Expand Down

0 comments on commit e14956d

Please sign in to comment.