Download the PHP package elegantly/laravel-money without Composer
On this page you can find all versions of the php package elegantly/laravel-money. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elegantly/laravel-money
More information about elegantly/laravel-money
Files in elegantly/laravel-money
Package laravel-money
Short Description Use Brick/Money in your Laravel app
License MIT
Homepage https://github.com/ElegantEngineeringTech/laravel-money
Informations about the package laravel-money
Elegant Integration of Brick/Money for Laravel
Table of Contents
- Introduction
- Features
- Installation
- Configuration
- Storing Money in the Database
- Usage
- Casting with a Column as Currency (Recommended)
- Casting with a Defined Currency
- Parsing Values to Money Instances
- Validation Rule
- Testing
- Changelog
- Contributing
- Security
- Credits
- License
Introduction
This package provides a seamless integration of Brick/Money with Laravel, allowing you to handle monetary values efficiently within your application.
Features
- MoneyCast: Cast model attributes to
Brick\Money\Money
. - MoneyParse: Convert various data types into
Brick\Money\Money
instances. - ValidMoney: Implement money validation rules.
Installation
Install the package via Composer:
Configuration
To customize the default settings, publish the configuration file:
The default configuration file (config/money.php
) contains:
Storing Money in the Database
The recommended way to store money in the database is to use a bigInteger
column for the amount and a string
column for the currency. This ensures precision and avoids floating-point errors. Store the amount in the smallest unit of currency (e.g., cents for USD, centimes for EUR). This approach prevents rounding issues and maintains accuracy in calculations.
Example migration:
Usage
Casting with a Column as Currency (Recommended)
If your database stores both the amount and the currency in separate columns, you can specify the currency column like this:
Casting with a Defined Currency
You can also define a specific currency for money casting instead of referencing a column:
Parsing Values to Money Instances
Convert strings, integers, or floats into Brick\Money\Money
instances using MoneyParser
:
Validation Rule
Using ValidMoney
in Livewire
Using ValidMoney
in Form Requests
Testing
Run the package tests with:
Changelog
Refer to the CHANGELOG for details on recent updates and modifications.
Contributing
Contributions are welcome! See CONTRIBUTING for guidelines.
Security
If you discover any security vulnerabilities, please review our security policy to report them responsibly.
Credits
- Quentin Gabriele
- All Contributors
License
This package is released under the MIT License. See LICENSE.md for details.
All versions of laravel-money with dependencies
brick/money Version ^0.10.0
illuminate/contracts Version ^10.0||^11.0||^12.0
spatie/laravel-package-tools Version ^1.13.0