Skip to main content
Back to packages
321 GitHub stars

Climactic/laravel-credits

View on GitHub

Description

A ledger-based Laravel package for managing credit-based systems in your application.

🔧 Setup Your Model

Add the HasCredits trait to any model that should handle credits:

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
}

💸 Transfers

Transfer credits between two models:

$sender->creditTransfer($recipient, 100.00, 'Paying to user for their service');

Recent Courses on Laravel Daily

Next.js Basics for Laravel Developers

11 lessons
58 min

Laravel 13 Starter Kit Teams and Customizations

10 lessons
33 min

How to Structure Laravel 13 Projects

16 lessons
1 h 32 min read