GithubHelp home page GithubHelp logo

npbreland / filament-money-field Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pelmered/filament-money-field

0.0 0.0 0.0 124 KB

Money field powered by Money PHP

License: MIT License

PHP 100.00%

filament-money-field's Introduction

Filament Money Field

Money field powered by Money PHP .

This package gives much better localization support for money fields in Filament than most other packages. For example when it comes to currency symbols and decimal and thousand separators. Especially for more obscure currencies.

Example of a money field with Swedish localization. This package would give "1234,56 kr", while most other solutions probably would give you something like "SEK 1234.56" which is not the correct format for Sweden.

Requirements

  • PHP 8.2 or higher
  • Filament 3.0 or higher
  • PHP Internationalization extension (intl)
  • The database column should be a integers with minor units (i.e. cents) and not a float (Floats should never be used for storing money).

Installation

composer require pelmered/filament-money-field

Configuration

Set the default currency and locale

Set the default options for currency and locale so that you don't have to set them for every field.

Option 1 (Recommended): Put the default options in your .env file.

MONEY_DEFAULT_LOCALE=sv_SE
MONEY_DEFAULT_CURRENCY=SEK

Option 2: Publish the config file and set the default options there.

php artisan vendor:publish --provider="Pelmered\FilamentMoneyField\FilamentMoneyFieldServiceProvider" --tag="config"

If you want to use the formatting mask on the MoneyInput component

This will auto format the input field as you type.

This is a bit experimental at the moment and is therefore disabled by default. Hopefully it will be improved in the future and enabled by default in the next major version. Please try it out and provide feedback.

MONEY_USE_INPUT_MASK=true // Defaults to false

Usage

InfoList

use Pelmered\FilamentMoneyField\Infolists\Components\MoneyEntry;

MoneyEntry::make('price'); // Defaults to USD and the current Laravel locale, or what you have set in your .env/config.

// The default can be set in the Infolist class with:
public static string $defaultCurrency = 'SEK';

MoneyEntry::make('price')
    ->currency('USD')
    ->locale('en_US');

MoneyEntry::make('price')
    ->currency('SEK')
    ->locale('sv_SE');

Form

use Filament\Forms\Components\MoneyField;

MoneyInput::make('price'); // Defaults to USD and the current Laravel locale, or what you have set in your .env/config.

MoneyInput::make('price')
    ->currency('USD')
    ->locale('en_US');

MoneyInput::make('price')
    ->currency('SEK')
    ->locale('sv_SE');


MoneyInput::make('price')
    ->currency('SEK')
    ->locale('sv_SE')
    ->minValue(0) // Do not allow negative values.
    ->maxValue(10000); // Add min and max value (in minor units, i.e. cents) to the input field. In this case no values over 100

Table column

use Pelmered\FilamentMoneyField\Tables\Columns\MoneyColumn;

MoneyColumn::make('price'); // Defaults to USD and the current Laravel locale, or what you have set in your .env/config.

MoneyColumn::make('price')
    ->currency('USD')
    ->locale('en_US');

MoneyColumn::make('price')
    ->currency('SEK')
    ->locale('sv_SE');

TDOO / Ideas for the future.

Contact me or create an issue if you want something of this, or something else. I appriciate if you could tell me a bit about your use case for that feature as well.

  • Improve test suite with tests for the individual components (I was struggling a bit with this. Help would be appriciated).
  • Add support for dynamic currency and locale based on current user.
  • Currency conversions. Set what base currency the value in the database is and then convert to the current users preferred currency on the fly. Not sure how edit/create should be handled in this case.

filament-money-field's People

Contributors

pelmered avatar kirkita avatar npbreland avatar luciorubeens avatar akshay-sood avatar saullo avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.