belongsTo(Team::class); } function user() { return $this->belongsTo(User::class); } function scopeActive($query) { return $query->where('active', 1); } protected static function boot() { parent::boot(); static::updating(function ($model) { if ($model->active == 1) { TeamUser::where('user_id', '!=', $model->user_id)->update(['active' => 0]); } }); } }