A comprehensive Laravel package to implement scoring systems effortlessly. Whether you're building leaderboards, calculating performance metrics, or managing gamification features, Laravel Score provides an intuitive API to define, calculate, and manage scores seamlessly. Perfect for applications requiring dynamic and flexible scoring mechanisms.
- Simple integration with Eloquent models.
- Support for customizable scoring rules.
- Designed for performance and scalability.
- Extensible and developer-friendly.
You can install the package with Composer.
composer require binafy/laravel-score
If you want to publish a config file you can use this command:
php artisan vendor:publish --tag="laravel-score-config"
If you want to publish the migrations you can use this command:
php artisan vendor:publish --tag="laravel-score-migrations"
For convenience, you can use this command to publish config, migration, and ... files:
php artisan vendor:publish --provider="Binafy\LaravelScore\Providers\LaravelScoreServiceProvider"
After publishing, run the php artisan migrate
command.
To enable scoring functionality, you need to use two traits:
On the model giving the score (e.g. User
):
use Binafy\LaravelScore\Traits\InteractWithScore;
use \Illuminate\Database\Eloquent\Model;
class User extends Model
{
use InteractWithScore;
}
On the model receiving the score (e.g. Photo
):
use Binafy\LaravelScore\Traits\Scoreable;
use Illuminate\Database\Eloquent\Model;
class Photo extends Model
{
use Scoreable;
}
To give a positive score to a scoreable model:
$user->addScore(
Model $scoreable,
int $score = 1,
int|null $userId = null
);
To assign a negative score:
$user->addNegativeScore(
Model $scoreable,
int|null $userId = null
);
You can check whether a model has already been scored by a specific user:
$user->hasScored(
Model $scoreable,
int|null $userId = null
): bool;
$photo->isScored(
?int $userId = null
): bool;
To get the total number of scores for a model:
$photo->getScoresCount(): int;
To remove an existing score:
$user->removeScore(Model $scoreable): bool;
$photo->removeScore(?int $userId = null): bool;
Thanks to all the people who contributed. Contributors.
If you discover any security-related issues, please email [email protected]
instead of using the issue tracker.
The changelog can be found in the CHANGELOG.md
file of the GitHub repository. It lists the changes, bug fixes, and improvements made to each version of the Laravel User Monitoring package.
The MIT License (MIT). Please see License File for more information.
If this package is helpful for you, you can buy a coffee for me :) ❤️
- Iranian Gateway: https://daramet.com/milwad_khosravi
- Paypal Gateway: SOON
- MetaMask Address:
0xf208a562c5a93DEf8450b656c3dbc1d0a53BDE58