app/Models/Character.php: Clear main character relationship if a main character is deleted.
This commit is contained in:
parent
23b5103b12
commit
4628ce85ac
1 changed files with 14 additions and 0 deletions
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue