Introducing Saksh Wallet: A Simple Wallet System for Laravel
Are you building a Laravel application that needs to manage user wallets, handle transactions, or track balances across multiple currencies? Look no further! I’m thrilled to announce the release of sakshsky/saksh-wallet, a lightweight, open-source Laravel package designed to simplify wallet functionality with a clean and intuitive API. Whether you’re creating an e-commerce platform, a freelance marketplace, or a gaming app, Saksh Wallet has you covered. In this post, I’ll walk you through what Saksh Wallet is, its key features, how to install and use it, and why it’s a great addition to your Laravel projects. Let’s dive in! What is Saksh Wallet? Saksh Wallet is a Laravel package that provides a robust and flexible wallet system for managing user transactions and balances. Built with Laravel 12 in mind, it leverages two database tables—wallet_transactions for transaction history and balances for current balances—to deliver a performant and scalable solution. The package is open-source, licensed under MIT, and available on Packagist at sakshsky/saksh-wallet. Whether you need to credit funds, debit with fees, or retrieve balance summaries, Saksh Wallet offers a straightforward API that integrates seamlessly into your Laravel application. Key Features Saksh Wallet is designed to be simple yet powerful. Here’s what it offers: Dual-Table Architecture: Uses wallet_transactions for tracking every credit and debit and balances for instant balance queries, ensuring performance and reliability. Multi-Currency Support: Handle transactions in any currency (e.g., USD, EUR, GBP) with per-currency balance tracking. Secure User Association: Links transactions and balances to users via user_id with foreign key constraints for data integrity. Flexible Transactions: Supports credits, debits with optional fees, references, and descriptions for detailed transaction records. Integrity Verification: Includes an Artisan command (saksh-wallet:verify) to check balance consistency against transaction history. Comprehensive Tests: Comes with PHPUnit tests to ensure reliability and ease of contribution. Open-Source Ready: Includes .gitignore, .gitattributes, CONTRIBUTING.md, and CHANGELOG.md for a complete package. Whether you’re managing in-game currencies, processing payments, or tracking user funds, Saksh Wallet provides the tools you need with minimal setup. Why Choose Saksh Wallet? There are several wallet packages for Laravel, like bavix/laravel-wallet, but Saksh Wallet stands out for its simplicity and focus on core functionality. Here’s why it’s worth considering: Lightweight: Minimal dependencies and a clean codebase make it easy to integrate and maintain. Performant: The balances table ensures O(1) balance queries, ideal for high-traffic applications. Developer-Friendly: Intuitive methods like addFunds, deductFunds, and getBalance make development a breeze. Extensible: Built with Laravel conventions, it’s easy to extend for custom features like transaction reversals or payment gateway integration. Open-Source: Licensed under MIT, it’s free to use and welcomes contributions from the community. Installation Getting started with Saksh Wallet is quick and easy. Follow these steps to add it to your Laravel 12 project: Install via Composer: composer require sakshsky/saksh-wallet Publish Migrations: The package includes a single migration to create the wallet_transactions and balances tables: php artisan vendor:publish --tag=saksh-wallet-migrations Run Migrations: Apply the migrations to set up the database schema: php artisan migrate That’s it! Your Laravel application is now ready to manage wallets. Note: Ensure your users table exists (standard in Laravel) and contains at least one user, as the package uses user_id with foreign key constraints. Usage Saksh Wallet provides a simple API for managing wallet operations. Here’s how you can use it in your Laravel application: Example: Controller Setup Create a controller to handle wallet operations:

Are you building a Laravel application that needs to manage user wallets, handle transactions, or track balances across multiple currencies? Look no further! I’m thrilled to announce the release of sakshsky/saksh-wallet
, a lightweight, open-source Laravel package designed to simplify wallet functionality with a clean and intuitive API. Whether you’re creating an e-commerce platform, a freelance marketplace, or a gaming app, Saksh Wallet has you covered.
In this post, I’ll walk you through what Saksh Wallet is, its key features, how to install and use it, and why it’s a great addition to your Laravel projects. Let’s dive in!
What is Saksh Wallet?
Saksh Wallet is a Laravel package that provides a robust and flexible wallet system for managing user transactions and balances. Built with Laravel 12 in mind, it leverages two database tables—wallet_transactions
for transaction history and balances
for current balances—to deliver a performant and scalable solution. The package is open-source, licensed under MIT, and available on Packagist at sakshsky/saksh-wallet.
Whether you need to credit funds, debit with fees, or retrieve balance summaries, Saksh Wallet offers a straightforward API that integrates seamlessly into your Laravel application.
Key Features
Saksh Wallet is designed to be simple yet powerful. Here’s what it offers:
-
Dual-Table Architecture: Uses
wallet_transactions
for tracking every credit and debit andbalances
for instant balance queries, ensuring performance and reliability. - Multi-Currency Support: Handle transactions in any currency (e.g., USD, EUR, GBP) with per-currency balance tracking.
-
Secure User Association: Links transactions and balances to users via
user_id
with foreign key constraints for data integrity. - Flexible Transactions: Supports credits, debits with optional fees, references, and descriptions for detailed transaction records.
-
Integrity Verification: Includes an Artisan command (
saksh-wallet:verify
) to check balance consistency against transaction history. - Comprehensive Tests: Comes with PHPUnit tests to ensure reliability and ease of contribution.
-
Open-Source Ready: Includes
.gitignore
,.gitattributes
,CONTRIBUTING.md
, andCHANGELOG.md
for a complete package.
Whether you’re managing in-game currencies, processing payments, or tracking user funds, Saksh Wallet provides the tools you need with minimal setup.
Why Choose Saksh Wallet?
There are several wallet packages for Laravel, like bavix/laravel-wallet
, but Saksh Wallet stands out for its simplicity and focus on core functionality. Here’s why it’s worth considering:
- Lightweight: Minimal dependencies and a clean codebase make it easy to integrate and maintain.
-
Performant: The
balances
table ensures O(1) balance queries, ideal for high-traffic applications. -
Developer-Friendly: Intuitive methods like
addFunds
,deductFunds
, andgetBalance
make development a breeze. - Extensible: Built with Laravel conventions, it’s easy to extend for custom features like transaction reversals or payment gateway integration.
- Open-Source: Licensed under MIT, it’s free to use and welcomes contributions from the community.
Installation
Getting started with Saksh Wallet is quick and easy. Follow these steps to add it to your Laravel 12 project:
- Install via Composer:
composer require sakshsky/saksh-wallet
-
Publish Migrations:
The package includes a single migration to create the
wallet_transactions
andbalances
tables:
php artisan vendor:publish --tag=saksh-wallet-migrations
- Run Migrations: Apply the migrations to set up the database schema:
php artisan migrate
That’s it! Your Laravel application is now ready to manage wallets.
Note: Ensure your users
table exists (standard in Laravel) and contains at least one user, as the package uses user_id
with foreign key constraints.
Usage
Saksh Wallet provides a simple API for managing wallet operations. Here’s how you can use it in your Laravel application:
Example: Controller Setup
Create a controller to handle wallet operations:
namespace App\Http\Controllers;
use Saksh\Wallet\Services\SakshWallet;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class WalletController extends Controller
{
protected $wallet;
public function __construct(SakshWallet $wallet)
{
$this->wallet = $wallet;
}
public function manageWallet(Request $request)
{
try {
$userId = Auth::id();
if (!$userId) {
return response()->json(['error' => 'User not authenticated'], 401);
}
// Credit 500 USD
$creditResult = $this->wallet->addFunds(
$userId,
500,
'USD',
'ref123',
'Salary payment'
);
// Debit 200 USD with a 5 USD fee
$debitResult = $this->wallet->deductFunds(
$userId,
200,
'USD',
'ref124',
'Grocery shopping',
5
);
// Get balance for USD
$balance = $this->wallet->getBalance($userId, 'USD');
// Get balance summary across all currencies
$summary = $this->wallet->sakshGetBalanceSummary($userId);
return response()->json([
'credit' => $creditResult,
'debit' => $debitResult,
'balance' => $balance,
'summary' => $summary,
]);
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 400);
}
}
}
Define Routes
Add a route to access the wallet functionality (e.g., in routes/api.php
):
use App\Http\Controllers\WalletController;
Route::get('/wallet', [WalletController::class, 'manageWallet'])->middleware('auth')->name('wallet.manage');
Example Output
Visiting /wallet
(with an authenticated user) might return:
{
"credit": "Credited 500 USD. New balance is 500",
"debit": "Debited 200 USD. New balance is 295",
"balance": {
"user_id": 1,
"currency": "USD",
"balance": 295
},
"summary": {
"user_id": 1,
"balance": {
"USD": 295
}
}
}
Verify Wallet Integrity
Run the included Artisan command to ensure balances match transaction history:
php artisan saksh-wallet:verify
This command checks for discrepancies and is useful for debugging or auditing.
Use Cases
Saksh Wallet is versatile and can be used in various scenarios:
- E-commerce: Allow customers to maintain a wallet for quick checkouts or refunds.
- Freelance Platforms: Manage payments to freelancers with platform fees.
- Gaming Apps: Handle in-game currencies for purchases or rewards.
- Financial Apps: Track user funds for budgeting or investment platforms.
The package’s multi-currency support makes it ideal for global applications, while its simple API ensures developers can integrate it quickly.