climactic/laravel-credits
Ledger-based Laravel package for credit systems like virtual currency, reward points, and balances. Supports deposits/withdrawals, transfers, transaction history, metadata, and querying—ideal for building auditable, credit-based features in your app.
CreditsAdded, CreditsDeducted, CreditsTransferred) enable seamless integration with Laravel’s event system, allowing for real-time notifications, analytics, or workflow triggers.SELECT FOR UPDATE) to prevent race conditions, which is critical for high-traffic applications (e.g., e-commerce, gaming). SQLite is explicitly unsupported for concurrent operations, forcing a clear architectural boundary.HasCredits trait integrates cleanly with existing models (e.g., User, Customer).allow_negative_balance) and events, allowing adaptation to specific business rules (e.g., overdraft policies).whereMetadata) perform full table scans. The package provides optimization guides, but this requires upfront planning and migration effort.credits table with metadata JSON column). Customizing the schema (e.g., for multi-tenancy) may require forks or extensions.100.00). Floating-point arithmetic risks precision errors in financial contexts. The package does not explicitly address this (e.g., via decimal columns or libraries like bcmath).decimal(10,2) vs. float)? Are there plans to integrate with libraries like moneyphp?order_id is numeric)?user.address.city) be indexed efficiently?HasCredits trait integrates seamlessly with existing models, requiring minimal boilerplate.assertDatabaseHas for transaction verification).User) to test the trait, events, and metadata features.php artisan vendor:publish --tag="credits-migrations" and adapt if needed (e.g., for multi-tenancy).creditAdd instead of manual DB updates).composer.json for exact requirements). May require adjustments for older versions.strict_types and named arguments usage).illuminate/database). No hard dependencies on non-Laravel packages.HasCredits trait to models.migrate.creditAdd, creditDeduct, and creditTransfer in business logic.CreditsAdded/CreditsDeducted (e.g., notifications).climactic/laravel-credits for breaking changes (e.g., new Laravel versions).SELECT FOR UPDATE logs or deadlock errors.EXPLAIN to analyze slow queries; verify indexes.CreditsAdded listeners).SELECT FOR UPDATE timeouts. Mitigate with:
order_id).credits tables by created_at or creditable_type if exceeding 10M rows.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Database connection loss | Transactions fail or hang | Use Laravel’s database retries and queue failed jobs. |
| Concurrent race conditions | Incorrect balances | Implement retry |
How can I help you explore Laravel packages today?