Skip to content

Instantly share code, notes, and snippets.

@PierreLebedel
Created February 8, 2024 13:06
Show Gist options
  • Save PierreLebedel/508a7ec081d4e3693eb75c492f038fd8 to your computer and use it in GitHub Desktop.
Save PierreLebedel/508a7ec081d4e3693eb75c492f038fd8 to your computer and use it in GitHub Desktop.
Blade directive for @price (EUR)
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
final class ViewServiceProvider extends ServiceProvider
{
public function boot(): void
{
// Replaces PHP native NumberFormatter special space by &nbsp;
Blade::directive('price', function($expression){
return "<?php echo \Illuminate\Support\Str::replace(' ','&nbsp;',\Illuminate\Support\Number::currency($expression, 'EUR', config('app.locale'))); ?>";
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment