feat: next level xp
This commit is contained in:
parent
c3246a0ec1
commit
eda8e02a47
|
|
@ -52,6 +52,15 @@ class User extends Authenticatable implements HasName, FilamentUser
|
||||||
'level_id'
|
'level_id'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The accessors to append to the model's array form.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $appends = [
|
||||||
|
'next_level_xp',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that should be hidden for serialization.
|
* The attributes that should be hidden for serialization.
|
||||||
*
|
*
|
||||||
|
|
@ -93,12 +102,18 @@ class User extends Authenticatable implements HasName, FilamentUser
|
||||||
$level = Level::where('xpThreshold', '<=', $this->xp)
|
$level = Level::where('xpThreshold', '<=', $this->xp)
|
||||||
->orderBy('xpThreshold', 'desc')
|
->orderBy('xpThreshold', 'desc')
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($level && $this->level_id !== $level->id) {
|
if ($level && $this->level_id !== $level->id) {
|
||||||
$this->level_id = $level->id;
|
$this->level_id = $level->id;
|
||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getNextLevelXpAttribute(): ?int
|
||||||
|
{
|
||||||
|
return Level::where('xpThreshold', '>', $this->xp)
|
||||||
|
->orderBy('xpThreshold', 'asc')
|
||||||
|
->value('xpThreshold');
|
||||||
|
}
|
||||||
public function getFilamentName(): string
|
public function getFilamentName(): string
|
||||||
{
|
{
|
||||||
return $this->username;
|
return $this->username;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue