diff --git a/app/Models/Character.php b/app/Models/Character.php index b9d45ca..18184b6 100644 --- a/app/Models/Character.php +++ b/app/Models/Character.php @@ -26,6 +26,20 @@ class Character extends Model 'class' ]; + public static function boot() + { + parent::boot(); + + static::deleted(function($character) { + + // Unset main character. + if ($character->isMain()) { + $character->user->main_character()->dissociate(); + $character->user->save(); + } + }); + } + /** * Get the route key for the model. *