← Fancy UI Curriculum

Gamification

XP, achievements, prizes and leaderboards for Laravel apps with laravel-fun-lab: awarding, how levels unlock achievements, reading the activity back, and the defaults that keep it safe.

0/4 lessons

0%

Profiles, metrics and awards

~8 min

particle-academy/laravel-fun-lab (LFL) calls itself analytics disguised as gamification: it tracks engagement through XP, achievements and prizes while capturing structured activity data that apps normally never record. It needs PHP 8.4+ and Laravel 13.

Install with composer require particle-academy/laravel-fun-lab, then php artisan lfl:install. Add the Awardable trait to any model, usually User, and it gets a Profile that tracks XP, achievements and prizes.

Define the game with LFL::setup(): a gamed metric (an XP track), its levels, level groups, achievements and prizes, for example LFL::setup(a: 'gamed-metric', with: ['slug' => 'combat-xp', 'name' => 'Combat XP']).

Then award, with fluent builders that end in save():

LFL::award('combat-xp')->to($user)->amount(50)->because('defeated boss')->save();
LFL::grant('first-login')->to($user)->because('completed onboarding')->save();

award adds XP to a metric; grant hands out an achievement or a prize. Check progress with LFL::hasLevel($user, 3, metric: 'combat-xp'), or by a level group with group:.