Level-Up is a Laravel package introducing gamification into your applications. Users earn experience points (XP) and levels through interactions, while also unl
Level-Up is a Laravel package introducing gamification into your applications. Users earn experience points (XP) and levels through interactions, while also unl
?style=for-the-badge&logo=laravel)
This package allows users to gain experience points (XP) and progress through levels by performing actions on your site. It can provide a simple way to track user progress and implement gamification elements into your application
You can install the package via composer:
composer require cjmellor/level-upYou can publish and run the migrations with:
php artisan vendor:publish --tag="level-up-migrations"
php artisan migrateYou can publish the config file with:
php artisan vendor:publish --tag="level-up-config"This is the contents of the published config file:
…If you're installing into an app that already has tables called experiences, levels, tiers, multipliers, challenges, or any of the package's other defaults, you can rename them via config — no need to patch published migrations.
Option 1 — Apply a single prefix to every package table:
Set an env var (no config publish required):
LEVEL_UP_TABLE_PREFIX=levelup_…or publish the config and edit the prefix line:
php artisan vendor:publish --tag=level-up-config// config/level-up.php
'table_prefix' => 'levelup_',All package tables now use the prefix: levelup_experiences, levelup_levels, levelup_tiers, levelup_multipliers, levelup_challenges, and so on.
Option 2 — Rename specific tables:
Edit the tables array in the published config:
'tables' => [
'experiences' => 'xp_log', // renamed
'levels' => 'user_tiers', // renamed
'tiers' => 'rank_brackets', // renamed
// leave the rest at their defaults
],Combining both: any value left equal to the default receives the table_prefix; any value you change is taken verbatim and the prefix is NOT applied. This lets you prefix everything but override one or two outliers:
'table_prefix' => 'lvl_',
'tables' => [
'levels' => 'xp_levels', // → 'xp_levels' (NO prefix)
// others stay default → all become 'lvl_'
],Upgrading from v1.x or earlier v2: the previous top-level
'table'config key (used to override only the experiences table) still works as a fallback. New installations should prefer'tables.experiences'instead.
Add the GiveExperience trait to your User model.
use LevelUp\Experience\Concerns\GiveExperience;
class User extends Model
{
use GiveExperience;
// ...
}Give XP points to a User
$user->addPoints(10);A new record will be added to the experiences table which stores the Users’ points. If a record already exists, it will be updated instead. All new records will be given a level_id of 1.
[!NOTE] If you didn't set up your Level structure yet, a default Level of
1will be added to get you started.
Deduct XP points from a User
$user->deductPoints(10);[!NOTE] Both
deductPointsandsetPointswill throw an exception if the User has no experience record.
Set XP points to a User
For an event where you just want to directly add a certain number of points to a User. Points can only be set if the User has an Experience Model.
$user->setPoints(10);Retrieve a Users’ points
$user->getPoints();Multipliers modify the experience points a User earns. They are managed via the database, so you can create, schedule, and toggle multipliers at runtime — no code deployments needed. This makes them ideal for building admin panels or managing promotional events.
Create a Multiplier
use LevelUp\Experience\Models\Multiplier;
Multiplier::create([
‘name’ => ‘WrestleMania Weekend’,
‘multiplier’ => 5,
‘is_active’ => true,
‘starts_at’ => ‘2026-04-05 00:00:00’,
‘expires_at’ => ‘2026-04-07 23:59:59’,
]);Active multipliers are automatically applied when a User earns points via addPoints(). Time-based multipliers activate and deactivate based on starts_at and expires_at. Non-time-based multipliers (like "Man UTD Win the League") are toggled via is_active.
Scope Multipliers to Users or Tiers
By default, a multiplier applies to all Users. You can restrict it to specific Users or Tiers:
// Scope to one or more tiers (variadic, idempotent)
$multiplier->scopeToTier($premiumTier, $diamondTier);
// Scope to one or more users (variadic, idempotent)
$multiplier->scopeToUser($user);
// Reverse either with unscope helpers
$multiplier->unscopeFromTier($diamondTier);
$multiplier->unscopeFromUser($user);
// Check whether a multiplier has any scopes
$multiplier->isGlobal(); // true if no users or tiers attachedIf a multiplier has no scopes, it applies to everyone. If it has scopes, it only applies to Users who match (either directly or via their Tier).
The tiers() and users() relations are standard belongsToMany — you can drop down to attach() / detach() / sync() for full control, but scopeToUser / scopeToTier are the recommended convenience methods because they're idempotent (they use syncWithoutDetaching under the hood, so calling them twice with the same model doesn't create duplicates).
Query Multipliers
Multiplier::active()->get(); // Currently active
Multiplier::active()->forUser($user)->get(); // Active for a specific user
Multiplier::scheduled()->get(); // Armed but starts_at is in the future
Multiplier::expired()->get(); // Past their expires_atStacking Strategy
When multiple multipliers are active, you can control how they combine via the stack_strategy config:
MULTIPLIER_STACK=compound # 2x × 5x = 10x (default)
MULTIPLIER_STACK=additive # 2x + 5x = 7x
MULTIPLIER_STACK=highest # max(2x, 5x) = 5xInline Multipliers
You can also pass a one-off multiplier directly when adding points. This participates in the configured stacking strategy alongside any active DB multipliers:
$user->addPoints(
amount: 10,
multiplier: 2
);PointsIncreased - When points are added.
public int $pointsAdded,
public int $totalPoints,
public string $type,
public ?string $reason,
public Model $user,
public ?array $multipliers, // Applied multipliers (if any)MultiplierApplied - When multipliers are applied during point addition.
public Model $user,
public Collection $multipliers, // DB multiplier models that were applied
public int $originalAmount, // Points before multipliers
public int $finalAmount, // Points after multipliers
public string $strategy, // 'compound', 'additive', or 'highest'PointsDecreased - When points are decreased.
public int $pointsDecreasedBy,
public int $totalPoints,
public ?string $reason,
public Model $user,[!NOTE] If you add points before setting up your levelling structure, a default Level of
1will be added to get you started.
The package has a handy facade to help you create your levels.
Level::add(
['level' => 1, 'next_level_experience' => null],
['level' => 2, 'next_level_experience' => 100],
['level' => 3, 'next_level_experience' => 250],
);Level 1 should always be null for the next_level_experience as it is the default starting point.
As soon as a User gains the correct number of points listed for the next level, they will level-up.
[!TIP] a User gains 50 points, they’ll still be on Level 1, but gets another 50 points, so the User will now move onto Level 2
See how many points until the next level
$user->nextLevelAt();Get the Users’ current Level
$user->getLevel();A level cap sets the maximum level that a user can reach. Once a user reaches the level cap, they will not be able to gain any more levels, even if they continue to earn experience points. The level cap is enabled by default and capped to level 100. These
options can be changed in the packages config file at config/level-up.php or by adding them to your .env file.
LEVEL_CAP_ENABLED=
LEVEL_CAP=
LEVEL_CAP_POINTS_CONTINUEBy default, even when a user hits the level cap, they will continue to earn experience points. To freeze this, so points do not increase once the cap is hit, turn on the points_continue option in the config file, or set it in the .env.
UserLevelledUp - When a User levels-up
public Model $user,
public int $levelThis is a feature that allows you to recognise and reward users for completing specific tasks or reaching certain milestones. You can define your own achievements and criteria for earning them. Achievements can be static or have progression. Static meaning the achievement can be earned instantly. Achievements with progression can be earned in increments, like an achievement can only be obtained once the progress is 100% complete.
There is no built-in methods for creating achievements, there is just an Achievement model that you can use as normal:
Achievement::create([
'name' => 'Hit Level 20',
'is_secret' => false,
'description' => 'When a User hits Level 20',
'image' => 'storage/app/achievements/level-20.png',
]);To use Achievements in your User model, you must first add the Trait.
// App\Models\User.php
use LevelUp\Experience\Concerns\HasAchievements;
class User extends Authenticable
{
use HasAchievements;
// ...
}Then you can start using its methods, like to grant a User an Achievement:
$achievement = Achievement::find(1);
$user->grantAchievement($achievement);To retrieve your Achievements:
$user->getUserAchievements();You can revoke an achievement from a user using the revokeAchievement method:
$user->revokeAchievement($achievement);The method will throw an exception if you try to revoke an achievement that the user doesn't have. You can revoke both standard and secret achievements, and it will also remove any associated progress.
When an achievement is revoked, a AchievementRevoked event is dispatched.
$user->grantAchievement(
achievement: $achievement,
progress: 50 // 50%
);[!NOTE] Achievement progress is capped to 100%
Progress is a percentage, so it can't tell you the absolute number behind it — how many games were played, articles read, and so on. Pass an optional count alongside the progress to track that number on the same achievement:
$user->grantAchievement(
achievement: $achievement,
progress: 50,
count: 5 // e.g. 5 games played
);Unlike progress, the count is open-ended — it isn't capped at 100.
Check at what progression your Achievements are at.
$user->achievementsWithProgress()->get();Check Achievements that have a certain amount of progression:
$user->achievementsWithSpecificProgress(25)->get();You can increment the progression of an Achievement up to 100.
$user->incrementAchievementProgress(
achievement: $achievement,
amount: 10
);Pass a count to also increment the achievement's absolute count by that amount:
$user->incrementAchievementProgress(
achievement: $achievement,
amount: 10,
count: 1 // one more game played
);A AchievementProgressionIncreased Event runs on method execution.
Secret achievements are achievements that are hidden from users until they are unlocked.
Secret achievements are made secret when created. If you want to make a non-secret Achievement secret, you can
No open issues yet, or sync has not completed.