Search by

roundly-consulting / credits-for-laravel

mihaliak

Manage credits / wallet balance on entity.

Package info

github.com/roundly-consulting/credits-for-laravel

pkg:composer/roundly-consulting/credits-for-laravel

Fund package maintenance!

Patreon

Statistics

Installs: 9

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-10-03 18:11 UTC

This package is auto-updated.

Last update: 2026-10-03 18:32:48 UTC


README

Credits for Laravel — Roundly open source

Latest release Tests Code style Donate Patreon Crypto

Credits for Laravel

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.

Installation

Requires PHP 8.4 (ext-bcmath), Laravel 12 or 13.

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.

Usage

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

Documentation

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.

Support our work

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.

Donate to Roundly open source Become a patron on Patreon Donate crypto: BTC, ETH, BNB or SOL

License

The MIT License (MIT). Please see License File for more information.