setono/tag-bag
Setono Tag Bag is a PHP library for collecting and rendering HTML tags like scripts, meta, and link elements. Add tags from anywhere in your code and output them later, making it ideal for Symfony apps that need clean, centralized head and body tag management.
composer require setono/tag-bag. Version 2.5.0 requires PHP 8.2+, so it pairs naturally with Laravel 11+ but drops PHP 8.0/8.1 environments still common on Laravel 9/10.TagBagInterface, TagBag, and TagInterface in src/, plus the concrete tag classes shipped by the package. Those define what you can add and how rendering works.AppServiceProvider:use Setono\TagBag\TagBag;
use Setono\TagBag\TagBagInterface;
public function register(): void
{
$this->app->scoped(TagBagInterface::class, TagBag::class);
}
Then render it in your layout:
<head>
{!! app(\Setono\TagBag\TagBagInterface::class)->render() !!}
</head>
If the core API differs slightly, follow the TagBagInterface contract in src/ rather than assuming Symfony bundle docs apply directly.
scoped() so tags do not leak between requests under Laravel Octane or long-running workers. A singleton is convenient in tests but dangerous in production.resources/views/partials/tags.blade.php, rather than scattering {!! ... !!} calls across views. This makes it easy to add position-specific rendering later if the bag supports separate sections or priorities.TagBagInterface so application code does not depend directly on the package namespace.TagInterface. When built-in Script, Style, Meta, or similar tag classes do not cover your markup, implement TagInterface for your own tag type and add it to the bag. This is the main extension point.TagBagInterface from the container, add a tag, perform the request, and assert the rendered markup with assertSee(..., false). For unit tests, instantiate TagBag directly and assert its rendered output.{!! !!} is intentional, but never place untrusted user input into a Script/Style tag. Treat tag content as trusted application markup.tinker or dump it before the layout renders:dump(app(\Setono\TagBag\TagBagInterface::class));
If tags are missing, confirm the bag is resolved from the container in both the adding code and the Blade layout, and that the layout partial is actually included.
code-quality-pack and PHPStan changes in v2.5.0 affect package development, not your application. Do not pin or install those just to use the library.setono/tag-bag to ^2.4. For PHP 8.2+ projects, ^2.5 is fine.How can I help you explore Laravel packages today?