- 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`.
29 lines
629 B
PHP
29 lines
629 B
PHP
<?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)));
|
|
?>");
|
|
}
|
|
}
|