No description or website provided.
PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
database/migrations Apply fixes from StyleCI (#14) Feb 12, 2018
src Apply fixes from StyleCI (#14) Feb 12, 2018
tests Enable strict types Aug 3, 2017
.editorconfig editorconfig Aug 3, 2017
.gitattributes gitattributes Aug 3, 2017
.gitignore first Nov 4, 2016
.travis.yml update deps Jan 29, 2018
LICENSE update deps Jan 29, 2018
README.md update readme Feb 16, 2018
composer.json update deps Feb 4, 2018
phpunit.xml.dist first Nov 4, 2016

README.md

Laravel Leadboard

Build Status PHP from Packagist Latest Version License

This package offers to reward entities with points and to create a ranking based on these points.

It is possible to reward, penalize, multiply, redeem and reset points and entities can be blacklisted/whitelisted which makes it possible to prevent certain entities to receive points.

Each entity will receive a rank based on its points which could be used to display a listing of the users with the most points or something like that.

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require faustbrian/laravel-leaderboard

At last you need to publish the migration and run the migration:

php artisan vendor:publish --provider="BrianFaust\Leaderboard\LeaderboardServiceProvider" && php artisan migrate

Usage

$user = App\User::find(1);

$events = [
    'CompletedProfile'      => 10,
    'SocialLoginFacebook'   => 5,
    'SocialLoginTwitter'    => 5,
    'SocialLoginGoogleplus' => 5,
];

// User filled out address, phone, email, etc.
if($user->completedProfile()) {
    $user->reward($events['CompletedProfile']);
}

// User added his Facebook profile
if($user->hasSocialProfile('facebook')) {
    $user->reward($events['SocialLoginFacebook']);
}

// User removed his Facebook profile
if($user->removedSocialProfile('facebook')) {
    $user->penalize($events['SocialLoginFacebook']);
}

// User purchased a premium package
$plan = App\Plan::findByTitle('Premium');

if($user->purchased($plan)) {
    $user->reward($plan->points);
}

// User wants to purchase something
$product = App\Product::find(1);

try {
    if($user->redeem($product->price)) {
        event(new ProductWasPurchased($product, $user));
    }
} catch(\BrianFaust\Leaderboard\Exceptions\InsufficientFundsException $e) {
    // Not enough points
    dd($e);
}

Functions

Reward the given amount of points.

$user->reward(10);

Remove the given amount of points.

$user->penalize(5);

Multiply all points by the given factor.

$user->multiply(2);

Redeem the given amount of points.

$user->redeem(15);

Reset all points to zero.

$user->reset();

Blacklist the user. This will disable all functions except for blacklist/whitelist.

$user->blacklist();

Whitelist the user.

$user->whitelist();

Testing

$ phpunit

Security

If you discover a security vulnerability within this package, please send an e-mail to hello@brianfaust.me. All security vulnerabilities will be promptly addressed.

Credits

License

MIT © Brian Faust