tizis/laravel-level-system

1.0.2 2021-05-22 13:24 UTC

This package is auto-updated.

Last update: 2024-04-29 04:47:11 UTC


README

composer require tizis/laravel-level-system

Publish Migrations & migrate

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

Publish Config & configure

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

Example

/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)