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}
You can store money for an exists model or create a new one.
1// WAY 12$person = Person::find(1);3$person->money('balance', 'USD', 100);4 5// WAY 26$person = Person::create([7 'balance' => 100.008]);
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.006echo $person->balance->amount; // 1007echo $person->balance->withName(); // 100.00 USD8echo $person->balance->withSymbol(); // $ 100.009echo $person->balance->toString(); // one hundred dollars {PHP Extension intl}