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!
This was helpful. I take the number_format much flexible
This is awsome thanks so much