Skip to content

Commit

Permalink
Merge pull request #64 from guptarakesh198/main
Browse files Browse the repository at this point in the history
adding null safety, when no experience records
  • Loading branch information
cjmellor authored Feb 28, 2024
2 parents 54d6d51 + 33fee9c commit 5c55884
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Concerns/GiveExperience.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function levelCapExceedsUserLevel(): bool

public function getLevel(): int
{
return $this->experience->status->level;
return $this->experience?->status?->level ?? 0;
}

public function experienceHistory(): HasMany
Expand Down Expand Up @@ -218,7 +218,7 @@ public function nextLevelAt(int $checkAgainst = null, bool $showAsPercentage = f

public function getPoints(): int
{
return $this->experience->experience_points;
return $this->experience?->experience_points ?? 0;
}

public function levelUp(int $to): void
Expand Down

0 comments on commit 5c55884

Please sign in to comment.