PHP code example of fannypack / ledger
1. Go to this page and download the library: Download fannypack/ledger 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/ */
fannypack / ledger example snippets
FannyPack\Ledger\LedgerServiceProvider::class,
'Ledger' => FannyPack\Ledger\Facades\Ledger::class,
namespace App;
use FannyPack\Ledger\Traits\Ledgerable;
use Illuminate\Database\Eloquent\Model;
class Account extends Model
{
use Ledgerable;
}
$account = Account::find(1);
$balance = Ledger::balance($account);
$account = Account::find(1);
$balance = $account->balance();
$account = Account::find(1);
Ledger::credit($account, $to, $amount, $reason);
$account = Account::find(1);
$account->credit($to, $amount, $reason);
$account = Account::find(1);
Ledger::debit($account, $from, $amount, $reason);
$account = Account::find(1);
$account->debit($from, $amount, $reason);
$account = Account::find(1);
$account2 = Account::find(2);
$account3 = Account::find(3);
Ledger::transfer($account, [$account2, $account3], $amount, $reason);
// or
Ledger::transfer($account, $account2, $amount, $reason);
Ledger::transfer($account, $account3, $amount, $reason);
$account = Account::find(1);
$account2 = Account::find(2);
$account3 = Account::find(3);
$account->transfer([$account2, $account3], $amount, $reason);
// or
$account->transfer($account2, $amount, $reason);
$account->transfer($account3, $amount, $reason);
$account = Account::find(1);
$entries = $account->entries();
$account = Account::find(1);
debits = $account->debits();
$account = Account::find(1);
debits = $account->credits();
<ledger></ledger>
php artisan vendor:publish --tag=ledger
php artisan migrate