A Simple Wallet Implementation for Laravel

A Simple Wallet Implementation for Laravel

laravel

Laravel Wallet by Stephen Jude is a simple wallet implementation for Laravel models:
1class User extends Authenticatable implements Wallet
2{
3 use HasWallet;
4}
Using the ‘HasWallet’ trait, you can add deposits, make withdrawals, and check the balance of the wallet for a given model:
1// Making deposits
2
3// returns the wallet balance: 200.22
4$user->deposit(200.22);
5
6// returns the wallet balance: 400.22
7$user->deposit(200);
Given a wallet balance from the above example, you can make withdrawals:
1// returns the wallet balance: 200.22
2$user->withdraw(200);
3
4// returns the wallet balance: 200
5$user->withdraw(0.22);
If you attempt to withdraw more than the amount in the wallet, the package will throw an exception:
1use Stephenjude\Wallet\Exceptions\ InsufficientFundException;
2
3try {
4 $user->withdraw(5_000);
5} catch (InsufficientFundException $e) {
6 // Code to handle insufficient funds…
7}

Related Blogs

Posted by admin | May 23, 2022
10 WordPress Plugins That Save Bloggers Time
1. WordPress.com Stats Personally, I feel it is essential for bloggers to track the activity on their blogs. You can make use of a web analytics tool, but it takes...
wordpress-top
Posted by admin | May 23, 2022
Top 5 Reasons Why WordPress Maintenance Is Essential
Although WordPress is most commonly used for blogging, you can also use it to host other types of sites, such as online stores and media galleries. The template system and...
blog-laravel-banner
Posted by admin | May 20, 2022
Laravel 9.13 Released
The Laravel team released 9.13 with a value() collection method, new test response helpers, an array map convenience method, and more: Release Notes You can see the complete list of...

What our clients say

Good things our clients have said about us