cjmellor / level-up

Level-Up is a Laravel package introducing gamification into your applications. Users earn experience points (XP) and levels through interactions, while also unlocking achievements. It promotes engagement, competition, and fun through its dynamic leaderboard feature. Customisable to fit your specific needs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Auditing Reason not adding to Db

spooksie opened this issue · comments

What happened?

First thing, I love this repo. Great job!

$user->addPoints(
    amount: 50,
    multiplier: 2,
    type: AuditType::Add->value,
    reason: "Some reason here",
);

Adds the amount and multiplier, but doesn't trigger the AuditType and reason.

How to reproduce the bug

$user->addPoints(
    amount: 50,
    multiplier: 2,
    type: AuditType::Add->value,
    reason: "Some reason here",
);

Package Version

0.0.6

PHP Version

8.2

Laravel Version

10.x

Which operating systems does with happen with?

macOS

Notes

No response

Hi @spooksie

Thanks for the kind words.

I'll have a look into this and see if I can reproduce the error and fix it.

Thanks.

Hey @spooksie

I can't seem to replicate this.

Do you have AUDIT_POINTS set to true in your .env ?

One thing to note about type -- yes, it's set to null but it is then set to be AuditType::Add->value by default

public function addPoints(
    int $amount,
    int $multiplier = null,
    string $type = null,
    string $reason = null
): Experience {
    if ($type === null) {
        $type = AuditType::Add->value;
    }

 // ...

Only PHP 8.2 lets you use an Enum as an expression and the package has a minimum version of 8.1

This did bring to my attention some tests that needed to be written though. These also replicate what you've said you've done and pass fine.

Do you have any further info you could provide to help me replicate this?

Thanks

I seemed to have missed AUDIT_POINTS=true in the .env

It now works a charm, thanks for explaining.