Manage credits / wallet balance on entity.
roundly-consulting/credits-for-laravel is a Laravel package for manage credits / wallet balance on entity..
It currently has 5 GitHub stars and 49 downloads on Packagist (latest version 1.1.2).
Install it with composer require roundly-consulting/credits-for-laravel.
Discover more Laravel packages by roundly-consulting
or browse all Laravel packages to compare alternatives.
Last updated
Credits and wallet balances on any Eloquent model. Every change is an immutable, time-stamped ledger row, so a balance is always the sum of its history — readable at any point in time, split into named buckets, and protected against overdraft and race conditions.
Requires PHP 8.4 (ext-bcmath), Laravel 12 or 13, and MySQL or PostgreSQL (SQLite for tests; SQL
Server is not supported).
composer require roundly-consulting/credits-for-laravel
php artisan vendor:publish --tag="credits-migrations"
php artisan migrate
If your creditable models have UUID/ULID keys, set CREDITS_KEY_TYPE before migrating.
Make any model creditable:
use Illuminate\Database\Eloquent\Model;
use RoundlyConsulting\Credits\Interfaces\Creditable;
use RoundlyConsulting\Credits\Traits\HasCredits;
final class User extends Model implements Creditable
{
use HasCredits;
}
Then grant, spend and read its credits:
use RoundlyConsulting\Credits\Facades\Credits;
Credits::for($user)->add(100, 'Welcome'); // a ledger row
Credits::for($user)->deduct(30, 'Order #42', ['order_id' => 42]); // InsufficientCreditsException below the floor
Credits::for($user)->balance(); // 70
Credits::for($user)->balance(now()->subWeek()); // as of a point in time
Credits::for($user)->has(50); // true
$points = Credits::for($user)->bucket('points'); // an independent pool
$points->add(500, 'Loyalty bonus');
$points->balance(); // 500
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/credits-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
The MIT License (MIT). Please see License File for more information.