1
0
Fork 0

app/Models/Character.php: Clear main character relationship if a main character is deleted.

This commit is contained in:
Henrik Hautakoski 2021-07-22 18:56:16 +02:00
parent 23b5103b12
commit 4628ce85ac

View file

@ -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.
*