rob*_*lls 10
我有使用模型事件的级联删除工作,例如在我绑定到已删除事件的Product模型中,因此我可以软删除所有关系:
// 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();
}
});
}
Run Code Online (Sandbox Code Playgroud)
我确实知道这在我的模型中是可能的:
public function delete() {
ChildTable::where('parent_id', $this->id)->delete();
ChildTable2::where('parent_id', $this->id)->delete();
parent::delete();
}
Run Code Online (Sandbox Code Playgroud)
但是对模型或表结构的任何更新都会导致附加/编辑......包括其他模型。
归档时间: |
|
查看次数: |
5951 次 |
最近记录: |