revert: add Blade directive for rendering user initials

- Introduced `DirectiveServiceProvider` to register custom Blade directives.
- Added `@initials` directive to generate and display uppercase initials from a given string.
- Registered the service provider in `bootstrap/providers.php`.
This commit is contained in:
= 2026-05-16 09:50:00 +00:00
parent 9b6af8135d
commit 3d086b2821
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
final class DirectiveServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*/
public function boot(): void
{
$this->registerInitialsDirective();
}
private function registerInitialsDirective(): void
{
Blade::directive('initials', fn ($expression) => "<?php
echo implode('', array_map(function(\$w) {
return strtoupper(\$w[0] ?? '');
}, explode(' ', $expression)));
?>");
}
}

View File

@ -5,4 +5,5 @@
return [ return [
App\Providers\AppServiceProvider::class, App\Providers\AppServiceProvider::class,
App\Providers\FortifyServiceProvider::class, App\Providers\FortifyServiceProvider::class,
App\Providers\DirectiveServiceProvider::class,
]; ];