nevadskiy / laravel-money
The package provides money and currency features for a Laravel application.
0.3.0
2023-06-14 21:24 UTC
Requires
- php: ^7.3|^8.0
- ext-intl: *
- ext-json: *
- laravel/framework: ^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^6.0|^7.0|^8.0
- phpunit/phpunit: ^8.0
README
💰 The package provides money and currency features for a Laravel application.
Installation
You can install the package via composer:
composer require nevadskiy/laravel-money
Documentation
Using money cast in the model
Any field can be cast into Money
instance. To make it castable, add the following code to your model:
use Nevadskiy\Money\Casts\AsMoney; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'cost' => AsMoney::class.':UAH', ];
Money cast with dynamic currency
Schema::create('products', function (Blueprint $table) { $table->bigInteger('cost')->unsigned(); $table->string('currency', 3); });
use Nevadskiy\Money\Casts\AsMoney; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'cost' => AsMoney::class.':[currency]', ];
To Do List
- use Symfony\Polyfill\Intl\Icu\Currencies for default registry