Skip to content

Commit

Permalink
Str::wrapHtmlTag($string, $tag = 'span', $attrs = [])
Browse files Browse the repository at this point in the history
  • Loading branch information
fzldn committed Sep 20, 2024
1 parent cf1fb7c commit d63729e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\User;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;

class AppServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -49,4 +50,19 @@ public function boot(): void
return null;
});
}

protected function macros(): void
{
Str::macro('wrapHtmlTag', function ($string, $tag = 'span', $attributes = []) {
$attrString = '';

if (!empty($attributes)) {
foreach ($attributes as $key => $value) {
$attrString .= " {$key}=\"{$value}\"";
}
}

return "<{$tag}{$attrString}>{$string}</{$tag}>";
});
}
}

0 comments on commit d63729e

Please sign in to comment.