tizis/laravel-level-system

1.0.2 2021-05-22 13:24 UTC

This package is auto-updated.

Last update: 2024-09-29 06:03:00 UTC


README

composer require tizis/laravel-level-system

发布迁移并迁移

php artisan vendor:publish --provider="tizis\LevelSystem\Providers\ServiceProvider" --tag=migrations
php artisan migrate //adding level & experience columns into 'users' table

发布配置并配置

php artisan vendor:publish --provider="tizis\LevelSystem\Providers\ServiceProvider" --tag=config

示例

/config/user-levels.php

return [
    'levels' => [
        1 => 100,
        2 => 200,
        3 => 300,
        4 => 400,
        5 => 500,
        ...
    ]
];
$user = User::where('id', 1)->first();
$service = new LevelService($user);  
$service->addProgress(500); // now user has 2nd level and 200 points of experience (500 - 100 - 200)