PHP code example of theamostafa / laravel-wallet

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

    

theamostafa / laravel-wallet example snippets


use Theamostafa\Wallet\Traits\HasWallet;

class User extends Model {

  use HasWallet;

}

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

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

$user->withdraw(1);
$user->balance; // 9

$user = User::first();

$transaction = $user->withdraw(
        amount: 1.33,
        meta: [
            'description' => "Refund from order #14"
        ]
    );
    $transaction->description // Refund from order #14
 

$user = User::first();

$user->transactions()->latest()->paginate(); 
bash
php artisan vendor:publish --tag="wallet-migrations"
php artisan migrate