particle-academy/laravel-fun-lab 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

particle-academy/laravel-fun-lab

Composer 安装命令:

composer require particle-academy/laravel-fun-lab

包简介

Analytics-driven gamification layer for Laravel applications. Track user engagement through awards, achievements, and prizes.

README 文档

README

Fancy UI suite

Powered by Tynn Latest Version License Laravel

Analytics disguised as gamification — turn user activity into meaningful engagement insights.

Laravel Fun Lab (LFL) is an analytics-driven gamification layer for Laravel applications. Track user engagement through XP, achievements, and prizes while capturing structured activity data that apps normally never track.

Features

  • 🎯 Event-Driven Architecture - Every action, reward, or update is an observable event
  • 🎮 GamedMetrics XP System - Create independent XP buckets with automatic level progression
  • 📊 MetricLevelGroups - Combine multiple XP metrics with weights for composite leveling
  • 🏆 Achievements - Define and grant achievements with auto-unlock on level-up
  • 🎁 Prizes - Reward users with virtual or physical prizes
  • 📈 Built-in Analytics - Query aggregate engagement data for behavioral insights
  • 🔌 Extensible - Macros, hooks, and custom implementations
  • Drop-In Simple - Install → Track → Award workflow

Installation

composer require particle-academy/laravel-fun-lab
php artisan lfl:install

Quick Start

1. Add the Awardable Trait

Add the Awardable trait to any model you want to gamify:

use LaravelFunLab\Traits\Awardable;

class User extends Authenticatable
{
    use Awardable;
}

// Works with any model!
class Team extends Model
{
    use Awardable;
}

The Awardable trait gives your model a Profile that tracks XP, achievements, and prizes.

2. Create GamedMetrics (XP Categories)

GamedMetrics are independent XP buckets. Each metric tracks its own XP and levels:

use LaravelFunLab\Facades\LFL;

// Create XP categories
LFL::setup(a: 'gamed-metric', with: ['slug' => 'combat-xp', 'name' => 'Combat XP']);
LFL::setup(a: 'gamed-metric', with: ['slug' => 'crafting-xp', 'name' => 'Crafting XP']);
LFL::setup(a: 'gamed-metric', with: ['slug' => 'social-xp', 'name' => 'Social XP']);

3. Define Levels for Metrics

Levels are XP thresholds that can auto-unlock achievements:

// Define levels for combat-xp
LFL::setup(a: 'metric-level', with: ['metric' => 'combat-xp', 'level' => 1, 'xp' => 0, 'name' => 'Novice']);
LFL::setup(a: 'metric-level', with: ['metric' => 'combat-xp', 'level' => 2, 'xp' => 100, 'name' => 'Apprentice']);
LFL::setup(a: 'metric-level', with: ['metric' => 'combat-xp', 'level' => 3, 'xp' => 500, 'name' => 'Warrior']);
LFL::setup(a: 'metric-level', with: ['metric' => 'combat-xp', 'level' => 4, 'xp' => 1000, 'name' => 'Champion']);

4. Award XP

Award XP using the fluent award() method:

// Award XP to a specific GamedMetric
LFL::award('combat-xp')
    ->to($user)
    ->amount(50)
    ->because('defeated boss')
    ->save();

// Check the profile
$profile = $user->getProfile();
echo $profile->total_xp; // Total XP across all metrics

5. Create and Grant Achievements

// Create an achievement
LFL::setup(a: 'achievement', with: ['slug' => 'first-login', 'name' => 'First Login', 'description' => 'Welcome!', 'icon' => 'star']);

// Grant the achievement
LFL::grant('first-login')
    ->to($user)
    ->because('completed onboarding')
    ->save();

// Check if user has an achievement
if ($user->hasAchievement('first-login')) {
    // ...
}

6. Create and Grant Prizes

// Create a prize
LFL::setup(
    a: 'prize',
    with: [
        'slug' => 'premium-access',
        'name' => '1 Month Premium Access',
        'type' => 'virtual',
        'inventory' => 100, // Limited quantity
    ]
);

// Grant the prize
LFL::grant('premium-access')
    ->to($user)
    ->because('won monthly contest')
    ->save();

7. Check Level Progress

// Check if user has reached a specific level in a metric
if (LFL::hasLevel($user, 3, metric: 'combat-xp')) {
    echo "You're a Warrior!";
}

// Check level in a metric group
if (LFL::hasLevel($user, 10, group: 'overall-power')) {
    echo "You've reached Overall Power Level 10!";
}

8. Create Metric Level Groups

Combine multiple metrics with weights for composite leveling:

// Create a group
LFL::setup(a: 'metric-level-group', with: ['slug' => 'overall-power', 'name' => 'Overall Power']);

// Add metrics to the group with weights
LFL::setup(a: 'metric-level-group-metric', with: ['group' => 'overall-power', 'metric' => 'combat-xp', 'weight' => 1.0]);
LFL::setup(a: 'metric-level-group-metric', with: ['group' => 'overall-power', 'metric' => 'crafting-xp', 'weight' => 0.5]);

// Define levels for the group
LFL::setup(a: 'metric-level-group-level', with: ['group' => 'overall-power', 'level' => 1, 'xp' => 0, 'name' => 'Beginner']);
LFL::setup(a: 'metric-level-group-level', with: ['group' => 'overall-power', 'level' => 10, 'xp' => 5000, 'name' => 'Expert']);

9. Leaderboards

// Get top users by XP
$leaders = LFL::leaderboard()
    ->for(User::class)
    ->by('xp')
    ->take(10);

API Summary

Method Purpose
LFL::setup() Create GamedMetrics, MetricLevels, MetricLevelGroups, Achievements, Prizes
LFL::award($metric) Award XP to a GamedMetric (fluent builder)
LFL::grant($slug) Grant an Achievement or Prize (fluent builder)
LFL::hasLevel($user, $level, metric: or group:) Check if user has reached a level
LFL::profile($user) Get the user's gamification profile
LFL::leaderboard() Build leaderboard queries
LFL::analytics() Build analytics queries

Documentation

Requirements

  • PHP 8.2+
  • Laravel 11.x or 12.x

License

MIT License - see LICENSE for details.

⭐ Star Fancy UI

If this package is useful to you, a quick ⭐ on the repo really helps us build a better kit. Thank you!

particle-academy/laravel-fun-lab 适用场景与选型建议

particle-academy/laravel-fun-lab 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 125 次下载、GitHub Stars 达 9, 最近一次更新时间为 2026 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「analytics」 「laravel」 「Gamification」 「leaderboards」 「achievements」 「engagement」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 particle-academy/laravel-fun-lab 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 particle-academy/laravel-fun-lab 我们能提供哪些服务?
定制开发 / 二次开发

基于 particle-academy/laravel-fun-lab 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 125
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 36
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-27