1. Go to this page and download the library: Download viveksingh/level-up library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
viveksingh / level-up example snippets
return [
/*
|--------------------------------------------------------------------------
| User Foreign Key
|--------------------------------------------------------------------------
|
| This value is the foreign key that will be used to relate the Experience model to the User model.
|
*/
'user' => [
'foreign_key' => 'user_id',
'model' => App\Models\User::class,
],
/*
|--------------------------------------------------------------------------
| Experience Table
|--------------------------------------------------------------------------
|
| This value is the name of the table that will be used to store experience data.
|
*/
'table' => 'experiences',
/*
|-----------------------------------------------------------------------
| Starting Level
|-----------------------------------------------------------------------
|
| The level that a User starts with.
|
*/
'starting_level' => 1,
/*
|-----------------------------------------------------------------------
| Multiplier Paths
|-----------------------------------------------------------------------
|
| Set the path and namespace for the Multiplier classes.
|
*/
'multiplier' => [
'enabled' => env(key: 'MULTIPLIER_ENABLED', default: true),
'path' => env(key: 'MULTIPLIER_PATH', default: app_path(path: 'Multipliers')),
'namespace' => env(key: 'MULTIPLIER_NAMESPACE', default: 'App\\Multipliers\\'),
],
/*
|-----------------------------------------------------------------------
| Level Cap
|-----------------------------------------------------------------------
|
| Set the maximum level a User can reach.
|
*/
'level_cap' => [
'enabled' => env(key: 'LEVEL_CAP_ENABLED', default: true),
'level' => env(key: 'LEVEL_CAP', default: 100),
'points_continue' => env(key: 'LEVEL_CAP_POINTS_CONTINUE', default: true),
],
/*
| -------------------------------------------------------------------------
| Audit
| -------------------------------------------------------------------------
|
| Set the audit configuration.
|
*/
'audit' => [
'enabled' => env(key: 'AUDIT_POINTS', default: false),
],
/*
| -------------------------------------------------------------------------
| Record streak history
| -------------------------------------------------------------------------
|
| Set the streak history configuration.
|
*/
'archive_streak_history' => [
'enabled' => env(key: 'ARCHIVE_STREAK_HISTORY_ENABLED', default: true),
],
/*
| -------------------------------------------------------------------------
| Default Streak Freeze Time
| -------------------------------------------------------------------------
|
| Set the default time in days that a streak will be frozen for.
|
*/
'freeze_duration' => env(key: 'STREAK_FREEZE_DURATION', default: 1),
];
use LevelUp\Experience\Concerns\GiveExperience;
class User extends Model
{
use GiveExperience;
// ...
}
$user->addPoints(10);
$user->deductPoints(10);
$user->setPoints(10);
$user->getPoints();
namespace LevelUp\Experience\Tests\Fixtures\Multipliers;
use LevelUp\Experience\Contracts\Multiplier;
class IsMonthDecember implements Multiplier
{
public bool $enabled = true;
public function qualifies(array $data): bool
{
return now()->month === 12;
}
public function setMultiplier(): int
{
return 2;
}
}
public function qualifies(array $data): bool
{
return now()->month === 12;
}