Laravel Money Format

Need to convert a float or string into a currency format in Laravel?

Here are two quick methods. Use PHP’s number_format() in your blade template.

{{ number_format($travelcosts, 2, ',', '.') }}

You can also add the following to your AppServiceProvider’s boot method.

//AppServiceProvider.php
    public function boot()
    {
        // Blade money directive
        Blade::directive('money', function ($amount) {
            return "<?php echo '$' . number_format($amount, 2); ?>";
        });
    }

// your blade file
@money($travelcost)

Good luck!

1 thought on “Laravel Money Format”

Leave a Comment