Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vyuldashev/nova-money-field
Money Field for Laravel Nova
https://github.com/vyuldashev/nova-money-field
currency laravel money nova php
Last synced: 9 days ago
JSON representation
Money Field for Laravel Nova
- Host: GitHub
- URL: https://github.com/vyuldashev/nova-money-field
- Owner: vyuldashev
- Created: 2018-08-24T11:03:24.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-03-22T14:33:38.000Z (8 months ago)
- Last Synced: 2024-10-23T13:32:35.649Z (15 days ago)
- Topics: currency, laravel, money, nova, php
- Language: Vue
- Homepage: https://novapackages.com/packages/vyuldashev/nova-money-field
- Size: 1.11 MB
- Stars: 74
- Watchers: 2
- Forks: 34
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Money Field for Laravel Nova
[![Latest Version on Packagist](https://img.shields.io/packagist/v/vyuldashev/nova-money-field.svg?style=flat-square)](https://packagist.org/packages/vyuldashev/nova-money-field)
[![Total Downloads](https://img.shields.io/packagist/dt/vyuldashev/nova-money-field.svg?style=flat-square)](https://packagist.org/packages/vyuldashev/nova-money-field)![screenshot 1](https://raw.githubusercontent.com/vyuldashev/nova-money-field/master/docs/user-details.png)
## Installation
You can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer:
```bash
composer require vyuldashev/nova-money-field
```## Usage
In resource:
```php
// ...
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:
```php
Money::make('Balance', 'EUR'),
```You may use `locale` method to define locale for formatting value, by default value will be formatted using browser locale:
```php
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:
```php
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.
```php
Money::make('Balance', 'EUR', 'remaining_balance'),
```