laravel-money, which @claybitner has posted, has its own peculiarities.
https://www.php.net/manual/en/function.money-format.php is deprecated since PHP 7.4 but is replaced by https://www.php.net/manual/en/numberformatter.formatcurrency.php
So I've written a simple helper function.
Create the file app/Helpers/helpers.php.
My simple function:
<?php
/**
* Format an amount to the given currency
*
* @return response()
*/
if (! function_exists('formatCurrency')) {
function formatCurrency($amount, $currency)
{
$fmt = new NumberFormatter( app()->getLocale(), NumberFormatter::CURRENCY );
return $fmt->formatCurrency($amount, $currency);
}
}
an in the composer.json add the "files" Part to autoload
"autoload": {
"psr-4": {
"App\": "app/",
"Database\Factories\": "database/factories/",
"Database\Seeders\": "database/seeders/"
},
"files": [
"app/Helpers/helpers.php"
]
},
Run composer dump-autoload once and you can use your formatCurrency helper function.
Works for me and maybe it helps someone.