PHP code example of webafra / laravel-user-wallet

1. Go to this page and download the library: Download webafra/laravel-user-wallet library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webafra / laravel-user-wallet example snippets



use Webafra\LaravelUserWallet\Interfaces\WalletOperations;
use Webafra\LaravelUserWallet\Traits\ManagesWallet;

class User extends Authenticatable implements WalletOperations
{
    use ManagesWallet;
}

namespace App\Enums;

enum WalletEnums: string
{
    case WALLET1 = 'wallet_1';
    case WALLET2 = 'wallet_2';
}


deposit(type: 'wallet_1', amount: 123.45, notes: null)

$user = auth()->user();
$user->deposit('wallet_1', 123.45);

$user = auth()->user();
$user->deposit('wallet_2', 67.89);

use Webafra\LaravelUserWallet\Facades\LaravelUserWallet;

$user = auth()->user();
LaravelUserWallet::deposit($user, 'wallet_1', 123.45);


$user = auth()->user();
$user->deposit('wallet_1', 67.89, 'You ordered pizza.');

pay(amount: 12.34, notes: null)

$user = auth()->user();
$user->pay(12.34);

use Webafra\LaravelUserWallet\Facades\LaravelUserWallet;

$user = auth()->user();
LaravelUserWallet::pay($user, 12.34); # decrease from all wallets
LaravelUserWallet::pay($user, 12.34, type: 'wallet_1');
LaravelUserWallet::pay($user, 12.34, type: 'wallet_1', notes: 'payment notes');

$user->walletBalance // Total combined balance available across all wallets

// Or using provided facade

LaravelUserWallet::checkBalance($user);

$user->getWalletBalanceByType('wallet_1') // Balance available in wallet_1
$user->getWalletBalanceByType('wallet_2') // Balance available in wallet_2

// Or using provided facade

LaravelUserWallet::walletBalanceByType($user, 'wallet_1');
bash
php artisan vendor:publish --tag="laravel-user-wallet-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="laravel-user-wallet-config"