From eda8e02a479517563041f13bbb184bf96e4a9a75 Mon Sep 17 00:00:00 2001 From: Leon Date: Fri, 9 Jan 2026 15:27:14 +0100 Subject: [PATCH] feat: next level xp --- app/Models/User.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Models/User.php b/app/Models/User.php index 0355d5c..ba79431 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -52,6 +52,15 @@ class User extends Authenticatable implements HasName, FilamentUser '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. * @@ -93,12 +102,18 @@ class User extends Authenticatable implements HasName, FilamentUser $level = Level::where('xpThreshold', '<=', $this->xp) ->orderBy('xpThreshold', 'desc') ->first(); - if ($level && $this->level_id !== $level->id) { $this->level_id = $level->id; $this->save(); } } + + public function getNextLevelXpAttribute(): ?int + { + return Level::where('xpThreshold', '>', $this->xp) + ->orderBy('xpThreshold', 'asc') + ->value('xpThreshold'); + } public function getFilamentName(): string { return $this->username;