PHPackages                             centrex/laravel-wallet - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. centrex/laravel-wallet

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

centrex/laravel-wallet
======================

Add wallet functionality in laravel application

v1.1.0(1y ago)02.5k[4 PRs](https://github.com/centrex/laravel-wallet/pulls)MITPHPPHP ^8.2|^8.3|^8.4CI passing

Since Dec 28Pushed 1mo agoCompare

[ Source](https://github.com/centrex/laravel-wallet)[ Packagist](https://packagist.org/packages/centrex/laravel-wallet)[ Docs](https://github.com/centrex/laravel-wallet)[ RSS](/packages/centrex-laravel-wallet/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (14)Versions (10)Used By (0)

Add wallet functionality in laravel application
===============================================

[](#add-wallet-functionality-in-laravel-application)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1de4c54612dfc1db31ef41e17fe146ae49451cef433c752e7272c2ecca341e62/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63656e747265782f6c61726176656c2d77616c6c65742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/centrex/laravel-wallet)[![GitHub Tests Action Status](https://camo.githubusercontent.com/eaa1235e66f1aebabd95ac9f9bcff83bd4b3ed32908b244c67c73d242892e5d0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f63656e747265782f6c61726176656c2d77616c6c65742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/centrex/laravel-wallet/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/bbaba876d2b97258b77e32dbb962b9c9b4c50b6c36db83decded858d9624e287/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f63656e747265782f6c61726176656c2d77616c6c65742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/centrex/laravel-wallet/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/711fee40208d14d7fc8352d0b3196e5e2583c0ed10087e813296d4ca31137f91/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63656e747265782f6c61726176656c2d77616c6c65743f7374796c653d666c61742d737175617265)](https://packagist.org/packages/centrex/laravel-wallet)

Easily add a virtual wallet to your Laravel models. Features multiple wallets and a ledger system to help keep track of all transactions in the wallets.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage Examples](#usage)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require centrex/laravel-wallet
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-wallet-config"
```

This is the contents of the published config file:

```
return [
];
```

Optionally, you can publish the views using

```
php artisan vendor:publish --tag="laravel-wallet-views"
```

Usage
-----

[](#usage)

First, you'll need to add the `HasWallets` trait to your model.

```
use Centrex\Wallet\Traits\HasWallets;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable, HasWallets;
}
```

By adding the `HasWallets` trait, you've essentially added all the wallet relationships to the model.

You can start by creating a wallet for the given model.

```
$user = User::find(1);

$wallet = $user->wallets()->create();
```

You can then increment the wallet balance by:

```
$wallet->incrementBalance(100);
```

Or decrement the balance by:

```
$wallet->decrementBalance(100);
```

To get the balance of the wallet, you can use the `balance` accessor:

```
$wallet->balance;
```

A wallet can be accessed using the `wallet()` method in the model:

```
$user->wallet();
```

You can set up multiple types of wallets by defining a `WalletType`. Simply create a wallet type entry in the `wallet_types` table and create a wallet using this wallet type.

```
use CoreProc\WalletPlus\Models\WalletType;

$walletType = WalletType::create([
    'name' => 'Peso Wallet',
    'decimals' => 2, // Set how many decimal points your wallet accepts here. Defaults to 0.
]);

$user->wallets()->create(['wallet_type_id' => $walletType->id]);
```

You can access a model's particular wallet type by using the `wallet()` method as well:

```
$pesoWallet = $user->wallet('Peso Wallet'); // This method also accepts the ID of the wallet type as a parameter

$pesoWallet->incrementBalance(100);

$pesoWallet->balance; // Returns the updated balance without having to refresh the model.
```

All movements made in the wallet are recorded in the `wallet_ledgers` table.

### Defining Transactions

[](#defining-transactions)

Ideally, we want to record all transactions concerning the wallet by linking it to a transaction model. Let's say we have a `PurchaseTransaction` model which holds the data of a purchase the user makes in our app.

```
use Illuminate\Database\Eloquent\Model;

class PurchaseTransaction extends Model
{
    //
}
```

We can link this `PurchaseTransaction` to the wallet ledger by implementing the `WalletTransaction` contract to this model and using this transaction to decrement (or increment, whatever the case may be) the wallet balance.

```
use CoreProc\WalletPlus\Contracts\WalletTransaction;
use Illuminate\Database\Eloquent\Model;

class PurchaseTransaction extends Model implements WalletTransaction
{
    public function getAmount()
    {
        return $this->amount;
    }
}
```

Now we can use this in the wallet:

```
$wallet = $user->wallet('Peso Wallet');

$purchaseTransaction = PurchaseTransaction::create([
    ...,
    'amount' => 100,
]);

$wallet->decrementBalance($purchaseTransaction);
```

By doing this, you will be able to see in the `wallet_ledgers` table the transaction that is related to the movement in the wallet.

Testing
-------

[](#testing)

🧹 Keep a modern codebase with **Pint**:

```
composer lint
```

✅ Run refactors using **Rector**

```
composer refacto
```

⚗️ Run static analysis using **PHPStan**:

```
composer test:types
```

✅ Run unit tests using **PEST**

```
composer test:unit
```

🚀 Run the entire test suite:

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [centrex](https://github.com/centrex)
- [All Contributors](../../contributors)
- [CoreProc/laravel-wallet-plus](https://github.com/CoreProc/laravel-wallet-plus)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance69

Regular maintenance activity

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~101 days

Total

5

Last Release

468d ago

Major Versions

v0.0.1 → v1.0.02023-12-30

PHP version history (3 changes)v0.0.1PHP ^8.0|^8.1

v1.0.0PHP ^8.1|^8.2

v1.1.0PHP ^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b62fd49922fd1bf7d55b94cc82ebc9f359af7f343b246a7e3a2642779c0b4e7?d=identicon)[rochi88](/maintainers/rochi88)

---

Top Contributors

[![rochi88](https://avatars.githubusercontent.com/u/29769944?v=4)](https://github.com/rochi88 "rochi88 (22 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (11 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")[![kolazsys](https://avatars.githubusercontent.com/u/110965082?v=4)](https://github.com/kolazsys "kolazsys (7 commits)")

---

Tags

laravellaravel-walletcentrex

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/centrex-laravel-wallet/health.svg)

```
[![Health](https://phpackages.com/badges/centrex-laravel-wallet/health.svg)](https://phpackages.com/packages/centrex-laravel-wallet)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
