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:
parent
9b6af8135d
commit
3d086b2821
28
app/Providers/DirectiveServiceProvider.php
Normal file
28
app/Providers/DirectiveServiceProvider.php
Normal 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)));
|
||||||
|
?>");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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,
|
||||||
];
|
];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user