---
title: "Validation, requests & collections — Money for Laravel | Roundly"
description: "Validate amounts and currency codes, read money from requests without floats, aggregate collections and return a JSON resource."
url: https://roundly-consulting.com/open-source/docs/money-for-laravel/http-validation
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Money for Laravel](https://roundly-consulting.com/open-source/docs/money-for-laravel.md)

# Validation, requests & collections

Validate money input with rule objects or string rules:

```php
use RoundlyConsulting\Money\Rules\CurrencyCode;
use RoundlyConsulting\Money\Rules\MoneyAmount;

$request->validate([
    'price'    => ['required', MoneyAmount::in('EUR')->positive()->max('99999.99')],
    'fee'      => [MoneyAmount::inCurrencyFrom('currency')->allowNegative()],
    'amount'   => [MoneyAmount::in('EUR')->localized('sk')],      // accepts "1 234,50"
    'currency' => ['required', (new CurrencyCode)->isoOnly()],
    'payout'   => ['required', new CurrencyCode(['EUR', 'CZK'])],
    'legacy'   => 'money_amount:EUR',
    'code'     => 'currency_code:EUR,CZK',
]);
```

- MoneyAmount::in($currency) or MoneyAmount::inCurrencyFrom($field) — a fixed currency, or one taken from a sibling input (held to currencies.allowed).
- min() / max() — ints and decimal strings are major units; a bound finer than the currency rounds inwards.
- positive() requires more than zero; allowNegative() lifts the default non-negative check.
- localized(?$locale) — accept localized input such as “1 234,50” through the parser.
- new CurrencyCode(?$allowed) — a registered code, limited to $allowed or currencies.allowed; ->isoOnly() refuses custom currencies.
- String rules: currency\_code, currency\_code:EUR,CZK and money\_amount:EUR (the default currency without a parameter).

Messages live under money::validation.\* — amount, precision, too\_large, negative, positive, min, max and currency — in English and Slovak. Publish money-translations to edit them.

## Reading money from a request

```php
$price = $request->money('price', 'EUR');              // JSON 1.1 → 1.10 EUR, not 1.11
$fee   = $request->money('fee', currencyKey: 'currency'); // currency from another input
$tip   = $request->money('tip');                       // money.default_currency; null when blank
```

- Missing or blank input returns null.
- An int is whole major units; a JSON float becomes its shortest round-trip decimal, so 1.1 is 110 cents, not 111.
- The currency comes from the argument, then the input at currencyKey, then money.default\_currency.
- Send amounts beyond 2⁵³ as JSON strings, and validate with MoneyAmount first.

## Collections

```php
$order->items->sumMoney(
    fn ($item) => $item->price->multiply($item->quantity),
    currencyIfEmpty: 'EUR',
);

$prices->minMoney();              // the items are Money
$products->maxMoney('price');     // a key or property path
$products->avgMoney('price');     // rounds once with money.rounding
```

sumMoney, minMoney, maxMoney and avgMoney work on Collection and LazyCollection (Eloquent collections inherit them). The value is null (the items are Money), a key or property path, or a callback. Empty collections follow Money::sum/min/max/average.

## API resources

```php
use RoundlyConsulting\Money\Http\Resources\MoneyResource;

return ['price' => MoneyResource::from($product->price)];
// {"minor":"1050","decimal":"10.50","currency":"USD","exponent":2,"formatted":"$10.50"}
```

MoneyResource::from() returns null for null. formatted uses the bound formatter in the app locale and is presentation only — clients should compute with minor.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/money-for-laravel.md)
