vyuldashev/nova-money-field

A Laravel Nova field for Money.
825,796 73
Install
composer require vyuldashev/nova-money-field
Latest Version:v2.0.0
PHP:^8.0
License:MIT
Last Updated:Mar 22, 2024
Links: GitHub  ·  Packagist
Maintainer: vyuldashev

Money Field for Laravel Nova

Latest Version on Packagist Total Downloads

screenshot 1

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require vyuldashev/nova-money-field

Usage

In resource:

// ...
use Vyuldashev\NovaMoneyField\Money;

public function fields(Request $request)
{
    return [
        // ...
        Money::make('Balance'),
    ];
}

USD currency is used by default, you can change this by passing second argument:

Money::make('Balance', 'EUR'),

You may use locale method to define locale for formatting value, by default value will be formatted using browser locale:

Money::make('Balance')->locale('ru-RU'),

If you store money values in database in minor units use storedInMinorUnits method. Field will automatically convert minor units to base value for displaying and to minor units for storing:

Money::make('Balance', 'EUR')->storedInMinorUnits(),

If you need to use a name that doesn't convert to the column name (eg 'Balance' as name and remaining_balance as column) you can pass this as the 3rd argument to the make/constructor.

Please Note: that this, along with all field column names, should be present and usable within your model class else you may encounter SQL errors.

Money::make('Balance', 'EUR', 'remaining_balance'),

Related Packages

maatwebsite/laravel-nova-excel

Supercharged Excel exports for Laravel Nova Resources

6,858,728 403
vyuldashev/nova-permission

A Laravel Nova tool for Spatie's Permission library.

2,621,375 430
unm/laravel4-opencloud

A laravel 4.1 service provider package that wraps the Rackspace/Openstack PHP SD...

4 7
spatie/nova-backup-tool

A Laravel Nova tool to backup your application.

590,379 361
spatie/nova-tail-tool

A Laravel Nova tool to display the application log.

129,391 119