Laravel 5.5 多币种应用最佳实践
Laravel 5.5 Multi Currency app best practices
有很多货币包,但我在多货币应用程序上没有找到任何东西。
理想情况下,多货币包应根据区域设置中存储的货币转换和显示货币。基础货币为美元。
所以调用{{currency(299)}}
应该将299转换成会话中存储的货币。
访问模型上的属性并覆盖 return 值:
public function getPriceAttribute($val)
{
$locale = config('app.locale');
return currency($val, 'USD', $locale);
}
假设您在模型中定义了一个 price
列,该列以 USD
格式存储。
currency
函数由软件包 like this one 提供。
如果您需要更精确和准确的转换计算器,您会想要使用类似 http://fixer.io/ - and there's a beautiful package that integrates this 的东西,我发现它非常有用。
有很多货币包,但我在多货币应用程序上没有找到任何东西。
理想情况下,多货币包应根据区域设置中存储的货币转换和显示货币。基础货币为美元。
所以调用{{currency(299)}}
应该将299转换成会话中存储的货币。
访问模型上的属性并覆盖 return 值:
public function getPriceAttribute($val)
{
$locale = config('app.locale');
return currency($val, 'USD', $locale);
}
假设您在模型中定义了一个 price
列,该列以 USD
格式存储。
currency
函数由软件包 like this one 提供。
如果您需要更精确和准确的转换计算器,您会想要使用类似 http://fixer.io/ - and there's a beautiful package that integrates this 的东西,我发现它非常有用。