Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Attempt to read property "next_level_experience" on null #20

Closed
lfcifuentes opened this issue Aug 1, 2023 · 1 comment · Fixed by #22
Closed

fix: Attempt to read property "next_level_experience" on null #20

lfcifuentes opened this issue Aug 1, 2023 · 1 comment · Fixed by #22
Labels
bug Something isn't working

Comments

@lfcifuentes
Copy link

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
@lfcifuentes lfcifuentes added the bug Something isn't working label Aug 1, 2023
@cjmellor
Copy link
Owner

cjmellor commented Aug 1, 2023

Thanks for the report @lfcifuentes -- gonna look into it!

@cjmellor cjmellor linked a pull request Aug 1, 2023 that will close this issue
@cjmellor cjmellor changed the title [Bug]: Attempt to read property "next_level_experience" on null fix: Attempt to read property "next_level_experience" on null Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants