• Reading time ~ 1 min
  • 20.02.2024

Laravel Wallet is designed for reliable and flexible transactions and handles the complex part of storing transactions in the database for precise calculations. It provides an intuitive API that is easy to use and straightforward to understand.

Once you have followed the setup instructions, you can set up the user model with the HasBalance trait:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use O21\LaravelWallet\Contracts\Payable;
use O21\LaravelWallet\Models\Concerns\HasBalance;

class User extends Model implements Payable
{
    use HasBalance;
}

Here are some possible commands you can use to work with a balance on the model. In the following examples, the $sender and $recipient implement the Payable interface via the HasBalance trait:

// Transfer money between sender and recipient
transfer(100, 'USD')->from($sender)->to($recipient)->commit();

// Deposit money into a recipient's account
deposit(100, 'USD')->to($recipient)->overcharge()->commit();

// Charge a user
charge(100, 'USD')->from($sender)->commit();

This package has resulted from the author using it privately on projects, honing it, and now releasing it as open-source. It includes safeguards for balance accuracy and a sophisticated rollback mechanism designed to revert modifications.

Learn More

To get started with this package, check out the Laravel Wallet documentation—this package is open source and available on GitHub. The documentation also includes a Withdrawal example to demonstrate best practices with this package.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297