The Credits package for Laravel is a ledger-based Laravel package for managing credit-based systems in your application. Perfect for virtual currencies, reward points, or any credit-based feature:
use Climactic\Credits\Traits\HasCredits; class User extends Model{ use HasCredits;} // Basic usage // Add credits$user->creditAdd(100.00, 'Subscription Activated'); // Deduct credits$user->creditDeduct(50.00, 'Purchase Made'); // Get current balance$balance = $user->creditBalance(); // Check if user has enough creditsif ($user->hasCredits(30.00)) { // Proceed with transaction}
With this package, you can also transfer credits, pull transactional history, historical balances, and more:
$sender->creditTransfer($recipient, 100.00, 'Paying to user for their service'); // Get last 10 transactions$history = $user->creditHistory(); // Get last 20 transactions in ascending order$history = $user->creditHistory(20, 'asc'); $balanceAsOf = $user->creditBalanceAt(new DateTime('2023-01-01'));
Main Features
- Credit transactions
- Credit transfers
- Events for adding, deducting, and transferring credits
- Balance tracking with running balance
- Transaction history
- Point-in-time balance lookup
- Transaction metadata support
- Efficient queries using running balance and indexes
💻 You can get started with this package on GitHub: Climactic/laravel-credits