Askedio / laravel-soft-cascade

Cascade Delete & Restore when using Laravel SoftDeletes
https://medium.com/asked-io/cascading-softdeletes-with-laravel-5-a1a9335a5b4d
MIT License
708 stars 64 forks source link

Add "Set null" behavior #130

Open rikipm opened 3 years ago

rikipm commented 3 years ago

Add behavior similar to SET NULL action. It will set relation column to NULL when referenced model is deleted.

For example

Class User extends Model {
  use SoftDeletes, SoftCascadeTrait;

  protected $softCascade = ['phone@setNull'];

  public function phone()
  {
    return $this->hasOne(Phone::class);
  }
}

Class Phone extends Model {
   use SoftDeletes;

  public function user()
  {
    return $this->belongsTo(User::class);
  }
}

Will set NULL in phones.user_id if user was soft deleted.

maguilar92 commented 2 years ago

You are free to make a PR with the improvement. I'm not using package anymore and only I will review PR's.