Pharaonic
Loading...

# Inclusion

This is how you can include Money into your model.

1namespace App\Models;
2 
3use Pharaonic\Laravel\Helpers\Traits\HasCustomAttributes;
4use Pharaonic\Laravel\Money\HasMoney;
5 
6class Person extends Model
7{
8 use HasCustomAttributes, HasMoney;
9 
10 // You can include your all monies names here.
11 protected $moneyAttributes = ['balance'];
12 ...
13}

# Create

You can store money for an exists model or create a new one.

1// WAY 1
2$person = Person::find(1);
3$person->money('balance', 'USD', 100);
4 
5// WAY 2
6$person = Person::create([
7 'balance' => 100.00
8]);

# Retrieve

This is how you can retreive the money data.

1$person = Person::find(1);
2 
3echo $person->money('balance', 'USD');
4 
5echo $person->balance; // 100.00
6echo $person->balance->amount; // 100
7echo $person->balance->withName(); // 100.00 USD
8echo $person->balance->withSymbol(); // $ 100.00
9echo $person->balance->toString(); // one hundred dollars {PHP Extension intl}

# withdraw

Withdraw part of the money.

1$person->balance->withdraw(0.50);

# deposit

Add a new amount.

1$person->balance->deposit(10.50);

# reset

Resetting money to zero.

1$person->balance->reset();

# isZero

Check if it equals Zero.

1$person->balance->isZero();

# isPositive

Check if it equals Zero.

1$person->balance->isPositive();

# isNegative

Check if it equals Zero.

1$person->balance->isNegative();