Adding defaults for Number helper #49254
Unanswered
raditzfarhan
asked this question in
Ideas
Replies: 2 comments 10 replies
-
Shouldn't this be ideally in |
Beta Was this translation helpful? Give feedback.
3 replies
-
What about setting a default currency just like setting a default locale? Like this: use Illuminate\Support\Number;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Number::useCurrency('MYR');
}
} I think this would be a great addition |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
My Problem
Right now, if I want to use
currency
apart fromUSD
, I need to specify the currency like soNumber::currency(1000, in: 'MYR')
every time I use it. This can quickly become a hassle if my application will only use that one currency. Below is the current code snippet withUSD
as the default currency.Proposed Idea
I think it would be nice if we can set a global defaults for
Number
helper like what we already have forPassword
rule. We can set thedefaults
in theboot
method of the application service provider. So in this way, we can set a default value, not only just for currency, it can also be use for something like locale, or precision. Here is the snippet of how it would look like:-Usage
Then, whenever I call the
currency
method, it will use back my default setting that I have set in application service providerboot
method without the need for me to specify the currency each time. My code will become a lot shorter and if i want to deploy my app to a different country, I can just change the currency value in thedefaults
without the need to touch the code anywhere else.What do you guys think? Any feedbacks or suggestions are welcomed.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions