Skip to content

Instantly share code, notes, and snippets.

@muhep06
Last active February 2, 2020 12:16
Show Gist options
  • Save muhep06/1a73462fcdf2d6ffd4bc566af9f8ffb8 to your computer and use it in GitHub Desktop.
Save muhep06/1a73462fcdf2d6ffd4bc566af9f8ffb8 to your computer and use it in GitHub Desktop.
Laravel Nova Custom Currency Field - call undefined function money_format() error fix
<?php
namespace App\Fields;
use Laravel\Nova\Fields\Number;
use NumberFormatter;
class Money extends Number
{
public $locale = "en_GB";
public $currency = "EUR";
/**
* Create a new field.
*
* @param string $name
* @param string|null $attribute
* @param mixed|null $resolveCallback
* @return void
*/
public function __construct($name, $attribute = null, $resolveCallback = null)
{
parent::__construct($name, $attribute, $resolveCallback);
$this->step('0.01')->displayUsing(function ($value) {
$formatter = new NumberFormatter($this->locale, NumberFormatter::CURRENCY);
return !is_null($value) ? $formatter->formatCurrency($value, $this->currency) : null;
});
}
/**
* @param string $locale
* @return $this
*/
public function locale(string $locale)
{
$this->locale = $locale;
return $this;
}
/**
* @param string $currency
* @return $this
*/
public function currency(string $currency)
{
$this->currency = $currency;
return $this;
}
}
@muhep06
Copy link
Author

muhep06 commented Feb 1, 2020

nova

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment