Laravel's Number facade has been enhanced with convenient methods for retrieving default locale and currency settings, simplifying internationalization in your applications. These additions streamline the process of handling regional settings and currency formatting, particularly useful when building applications that serve users across different regions.
use Illuminate\Support\Number;// Quick access to defaults$locale = Number::defaultLocale();$currency = Number::defaultCurrency();
Let's explore a practical example of an international order processing system:
<?php namespace App\Services; use App\Models\Order;use Illuminate\Support\Number;use App\Events\OrderProcessed; class OrderProcessor{ public function formatOrderSummary(Order $order, ?string $userLocale = null) { $locale = $userLocale ?? Number::defaultLocale(); $currency = $order->currency ?? Number::defaultCurrency(); return [ 'order_number' => $order->reference, 'subtotal' => Number::currency($order->subtotal, in: $currency), 'tax' => Number::currency($order->tax, in: $currency), 'total' => Number::currency($order->total, in: $currency), 'formatted_date' => $order->created_at->locale($locale)->isoFormat('LLLL'), 'meta' => [ 'display_locale' => $locale, 'currency' => $currency, 'exchange_rate' => $this->getExchangeRate( from: Number::defaultCurrency(), to: $currency ) ] ]; } protected function getExchangeRate(string $from, string $to): float { // Exchange rate calculation logic return 1.0; }}
These new helper methods simplify access to your application's default regional settings, making it easier to handle international formatting and currency display.
