无法覆盖模型laravel 5.6中的引导方法

时间:2018-06-04 10:38:10

标签: laravel-5.6

我尝试使用以下代码覆盖laravel 5.6中的boot()方法

class Organization extends Model
{
    use SoftDeletes;
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $dates = ['deleted_at'];
    protected $table = 'organizations';
    //protected $cascadeDeletes = ['organization_members'];

protected $fillable = ['name', 'user_id','logo','description','status'];

protected static function boot ()
{
    parent::boot();

    Organization::deleting(function (Organization $organization) {


    foreach ($organization->organization_members()->get() as $organization_member) {

        $organization_member->delete();
     }

    });
}
public function organization_members()
{
   $this->hasMany(OrganizationMembers::class);
}

}

组织是父模型,组织成员是具有引用组织中的id的外键的子模型。我试图在组织模型中删除()事件时删除组织成员。但是它没有被删除而且从不进入引导方法

0 个答案:

没有答案