Laravel Packages

Manage Credit-based Systems in Laravel

Published
Manage Credit-based Systems in Laravel image

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 credits
if ($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

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article