brokeyourbike/money-validation-laravel

Validation rules for Money and Currency

1.0.2 2023-05-14 22:00 UTC

This package is auto-updated.

Last update: 2024-12-20 14:51:00 UTC


README

Latest Stable Version Total Downloads Maintainability Test Coverage

Validation rules for Money and Currency

Installation

composer require brokeyourbike/money-validation-laravel

Usage

Package uses service container for currencies resolution. You can set it in your AppServiceProvider

use Money\Currencies\ISOCurrencies;
use Money\Currencies;

public function register()
{
    $this->app->singleton(Currencies::class, function () {
        return new ISOCurrencies();
    });
}
use Illuminate\Foundation\Http\FormRequest;
use BrokeYourBike\MoneyValidation\IsValidCurrency;

class ExampleRequest extends FormRequest
{
    public function rules()
    {
        return [
            'currency_code' => [
                'required',
                'string',
                'size:3',
                new IsValidCurrency(),
            ],
        ];
    }
}

Authors

License

Mozilla Public License v2.0