nevadskiy/laravel-money

The package provides money and currency features for a Laravel application.

0.3.0 2023-06-14 21:24 UTC

This package is auto-updated.

Last update: 2024-10-15 00:26:10 UTC


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