fix: Attempt to read property "next_level_experience" on null
lfcifuentes opened this issue · 1 comments
What happened?
Reaching max level and calling nextLevelAt
function throws error Attempt to read property "next_level_experience" on null
How to reproduce the bug
I created 4 levels:
Level::add(
['level' => 1, 'next_level_experience' => null],
['level' => 2, 'next_level_experience' => 100],
['level' => 3, 'next_level_experience' => 250],
['level' => 4, 'next_level_experience' => 500],
);
implement a route where I do this:
$user = \App\Models\User::find(1);
$user->addPoints(50);
echo $user->getLevel();
echo $user->getPoints();
echo $user->nextLevelAt();
Run api calls to the route repeatedly
When the user reaches the maximum level, call the function nextLevelAt
Environment Variables
LEVEL_CAP_ENABLED=true
LEVEL_CAP=4
LEVEL_CAP_POINTS_CONTINUE=true
AUDIT_POINTS=true
Package Version
0.0.5
PHP Version
8.2.8
Laravel Version
10.10
Which operating systems does with happen with?
macOS
Notes
The error seems to be on line 152 of the vendor/cjmellor/level-up/src/Concerns/GiveExperience.php
file when trying to look for a level higher than 4 which is the maximum set in my environment variables.
Could it be that I am missing some configuration?
I am using:
- Docker version 20.10.17, build 100c701
- PHP 8.2-fpm
- Postgres 13
Thanks for the report @lfcifuentes -- gonna look into it!