### Install with Composer Source: https://github.com/roundly-consulting/money-for-laravel/blob/main/README.md Install the package using Composer. Requires PHP 8.4 with ext-bcmath and ext-intl, and Laravel 12 or 13. ```bash composer require roundly-consulting/money-for-laravel ``` -------------------------------- ### Currency conversion with Exchange facade Source: https://github.com/roundly-consulting/money-for-laravel/blob/main/README.md Convert Money instances to other currencies using the Exchange facade. Default ECB rates require no setup. convertTo returns a Money in the target currency; convertWithRate returns a Conversion object with original, converted, and rate. ```php use RoundlyConsulting\Money\Facades\Exchange; $product->price->convertTo('USD'); // Money in USD at today's rate Exchange::convertWithRate($product->price, 'CZK'); // Conversion: original, converted, rate ``` -------------------------------- ### Eloquent migration and model with AsMoney cast Source: https://github.com/roundly-consulting/money-for-laravel/blob/main/README.md Create a products table with a money column and define a model using the AsMoney cast. The money method creates decimal(38,0) price and price_currency columns. ```php use RoundlyConsulting\Money\Casts\AsMoney; Schema::create('products', function (Blueprint $table) { $table->id(); $table->money('price'); // decimal(38,0) price + price_currency $table->timestamps(); }); final class Product extends Model { protected $fillable = ['price']; protected function casts(): array { return ['price' => AsMoney::class]; } } $product = Product::create(['price' => Money::ofMajor('19.99', 'EUR')]); ``` -------------------------------- ### Basic Money arithmetic and allocation Source: https://github.com/roundly-consulting/money-for-laravel/blob/main/README.md Create Money instances from major or minor units, perform exact arithmetic, allocate amounts, and format. Currency mismatches throw CurrencyMismatch. ```php use RoundlyConsulting\Money\Money; $price = Money::ofMajor('19.99', 'EUR'); // minor "1999", never a float $total = $price->add(Money::ofMinor(250, 'EUR'))->multiply(3); // 67.47 EUR, exact [$a, $b, $c] = $total->allocate(1, 1, 1); // parts always sum back to $total $total->add(Money::ofMajor('1', 'USD')); // throws CurrencyMismatch $total->toDecimal(); // "67.47" $total->format('sk'); // "67,47 €" ```