PHP code example of krunaldodiya / wallet

1. Go to this page and download the library: Download krunaldodiya/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/ */

    

krunaldodiya / wallet example snippets



use KD\Wallet\Traits\HasWallet;

class User extends Model
{
    use HasWallet;

    ...
}

$user = User::find(1);
$user->balance; // 0

$transaction = $user->createTransaction(100, 'deposit', ['description' => 'transaction description'])
$user->deposit($transaction->transaction_id);
$user->balance; // 100

$transaction = $user->createTransaction(50, 'withdraw', ['description' => 'transaction description'])
$user->withdraw($transaction->transaction_id);
$user->balance; // 50

$transaction = $user->createTransaction(200, 'withdraw', ['description' => 'transaction description'])
$user->forceWithdraw($transaction->transaction_id);
$user->balance; // -150
bash
php artisan vendor:publish --provider="KD\Wallet\WalletServiceProvider" --tag=migrations
bash
php artisan vendor:publish --provider="KD\Wallet\WalletServiceProvider" --tag=config