PHP code example of anexponent / laravel-wallet

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

    

anexponent / laravel-wallet example snippets


    return [
        'user_model' => App\Models\User::class,
        'wallet_model' => Anexponent\Wallet\Wallet::class,
        'transaction_model' => Anexponent\Wallet\Transaction::class,
    ];


use Anexponent\Wallet\HasWallet;

class User extends Model
{
    use HasWallet;

    ...
}

$user->wallet()->firstOrCreate([]);

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

$user->deposit(100);
$user->balance; // 100

$user->withdraw(50);
$user->balance; // 50

$user->forceWithdraw(200);
$user->balance; // -150

$user = User::find(1);
$user->deposit(100, 'deposit', ['stripe_source' => 'ch_BEV2Iih1yzbf4G3HNsfOQ07h', 'description' => 'Deposit of 100 credits from Stripe Payment']);
$user->withdraw(10, 'withdraw', ['description' => 'Purchase of Item #1234']);
 
$transactions = $user->transactions;


$transaction->signed_amount;
bash
php artisan migrate

bash
php artisan vendor:publish --provider="Anexponent\Wallet\WalletServiceProvider" --tag=migrations

bash
php artisan vendor:publish --provider="Anexponent\Wallet\WalletServiceProvider" --tag=config