Laravel 5: cascade soft delete

后端 未结 4 1622
醉话见心
醉话见心 2020-12-24 07:54

I am having offers and services table.

Service(s) is a child of an offer. So far I have established functionality for soft deletin

4条回答
  •  佛祖请我去吃肉
    2020-12-24 08:24

    I have put this code in Offer model:

    protected static function boot() {
        parent::boot();
    
        static::deleting(function($offer) {
            $offer->services()->delete();
        });
    }
    

    And added missing

    use SoftDeletes;
    protected $dates = ['deleted_at'];
    

    in the Service model.

提交回复
热议问题