brokeyourbike/money-validation-laravel

Validation rules for Money and Currency

1.0.1 2022-04-06 09:47 UTC

This package is auto-updated.

Last update: 2022-05-06 09:59:03 UTC


README

Latest Stable Version Total Downloads License: MPL-2.0 tests 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