In this episode, we dive into how Laravel's Number Helper can make working with currencies a lot easier. First, we take a look at how the Number Helper can format a value as currency, and by default, it uses USD (US Dollars). But what if you're not working with dollars all the time?
We'll talk about how you can specify different currencies on the fly by passing a currency code (like GBP for British Pounds), but doing that every single time can get annoying. That's where Laravel's new feature comes in: you can globally set a default currency for all number formatting using the useCurrency
method.
We show you how to use this in your application. You can set this globally, for example, in your AppServiceProvider's boot method, to make sure everything defaults to your desired currency. This is super helpful if you always work with a single currency or if you want to set it based on a value from your database, like a user's preference.
In the end, we test it out, and everything now shows up in the currency you set by default, making your life much easier. No more repeating yourself! If you're building a multi-tenant app or just want consistent currency formatting, this feature is a real timesaver.