### Install Credits for Laravel with Composer and Artisan Source: https://github.com/roundly-consulting/credits-for-laravel/blob/main/README.md Run these commands to install the package, publish its migrations, and run migrations. Requires PHP 8.4 with ext-bcmath, Laravel 12 or 13, and MySQL or PostgreSQL (SQLite for tests; SQL Server not supported). Set CREDITS_KEY_TYPE before migrating if your models use UUID/ULID keys. ```bash composer require roundly-consulting/credits-for-laravel php artisan vendor:publish --tag="credits-migrations" php artisan migrate ``` -------------------------------- ### Make an Eloquent Model Creditable with HasCredits Source: https://github.com/roundly-consulting/credits-for-laravel/blob/main/README.md Use the HasCredits trait and implement the Creditable interface to enable credit functionality on any Eloquent model. This example shows a User model. ```php use Illuminate\Database\Eloquent\Model; use RoundlyConsulting\Credits\Interfaces\Creditable; use RoundlyConsulting\Credits\Traits\HasCredits; final class User extends Model implements Creditable { use HasCredits; } ``` -------------------------------- ### Add, Deduct, and Query Credits with Credits Facade Source: https://github.com/roundly-consulting/credits-for-laravel/blob/main/README.md Demonstrates the main Credits facade methods: add, deduct, balance (including as-of a point in time), has, and bucket. Deducting below the floor throws InsufficientCreditsException. Buckets create independent credit pools. ```php 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 ```