Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Twig Component Preview Bundle Laravel Package

plixus/twig-component-preview-bundle

A Symfony bundle that adds a preview environment for Twig components, letting developers render and inspect individual components in isolation during development. Useful for building and reviewing UI pieces outside full page templates.

View on GitHub
Deep Wiki
Context7

Getting Started

This package generates Blade component names from PHP classes. The v1.0.1 release fixes the namespace configuration problem that previously surfaced as Could not generate a component name for class... by introducing a name_prefix config parameter — so the first thing to do on any existing install is re-publish (or diff) the config file, because the new key will not exist in a config you published under an earlier version.

  1. composer require <vendor>/<package> (constraint ^1.0.1 — anything below it will keep hitting the naming error under namespaced classes).
  2. Publish the config: php artisan vendor:publish --tag=<package>-config (use --force only after diffing against your current file; see Gotchas).
  3. Set name_prefix to something stable and project-specific, e.g. 'name_prefix' => 'app'. This value is folded into the generated component name and is what stops two classes with the same short name in different namespaces from colliding.
  4. php artisan config:clear (or optimize:clear), then run the generator/registration command for one class and confirm the resulting Blade file renders with <x-... />.

Look first at: the published config file (that's where name_prefix lives), then the package's service provider to see whether components are registered at boot from config or generated ahead of time by an artisan command. Those two facts determine almost everything about how you'll integrate it.

First real use case: take one existing namespaced class (a view model, a DTO, a domain-specific presenter) and expose it as a component. Getting a single App\ViewModels\InvoiceSummary → <x-app-invoice-summary /> working end-to-end proves the prefix, the namespace mapping, and the view resolution path all at once. Do this before touching a second class.

Implementation Patterns

Pin the prefix per application, not per module. name_prefix is global config, so treat it as an application-level constant set once in .env (NAME_PREFIX=app) and read via config(). Changing it later renames every generated component, which is a silent breaking change for every Blade file that references them.

Namespace → component name mapping. The package derives a name from the class's namespace relative to whatever root namespace you configure. In practice: configure the root namespace(s) that contain your component-eligible classes, and keep that list narrow. Pointing it at App\ wholesale means every new class becomes a candidate component, including things you never intended to render.

Domain/module isolation. If you're on a modular codebase, the natural pattern is one root namespace per module plus a distinct prefix, e.g. billing and reports, yielding <x-billing-invoice-total /> and <x-reports-invoice-total />. This is exactly the collision the name_prefix fix addresses — two InvoiceTotal classes in different namespaces previously produced an unresolvable name. If you're upgrading, audit for classes that were silently skipped or collided before v1.0.1; they may now start generating names, which means new components appearing in your build.

Generated vs. runtime. If the package writes component classes/files, run generation as part of your build or a dedicated artisan step rather than on every request, and commit the output. If it registers dynamically at boot, watch boot cost on large directories and verify it plays nicely with php artisan optimize / config caching.

Testing. Add a small smoke test that asserts each configured namespace produces a non-empty component name — this is the assertion that would have caught the v1.0.1 bug. A unit test iterating registered classes and calling the name generator is cheap insurance against the next namespace change.

Blade integration. Prefer the <x-prefix-name /> syntax over @component directives so the generated name mapping stays visible at the call site. Keep props/attributes documented next to the class rather than only in the Blade file.

Gotchas and Tips

  • The upgrade is config-required, not just a version bump. composer update alone will not fix the Could not generate a component name for class... error — without name_prefix present in your published config, behaviour depends on whether the package ships a merged default. Diff your config against the vendor copy immediately after updating.
  • vendor:publish --force will clobber your tuned namespace list. Publish to a temp tag or diff manually; only the new name_prefix key should be added.
  • Config cache is the #1 source of "the fix didn't work". After editing config, php artisan config:clear. If you're on a deploy pipeline that runs config:cache, the stale value will survive a code deploy.
  • Silent no-ops. A class that falls outside every configured root namespace is skipped without an error in most implementations of this pattern. When a component "doesn't exist", check the namespace mapping before you check the path.
  • Nested namespaces flatten predictably. App\Billing\Invoices\Summary typically becomes billing-invoices-summary (or dotted equivalents). Long chains plus a prefix can exceed whatever length cap the generator enforces — keep nesting shallow and names short.
  • Prefix characters matter. Hyphens vs. underscores vs. dots in name_prefix affect the generated component tag; pick something kebab-safe so <x-...> doesn't require quoting or awkward escaping.
  • Debugging the name generation. When a name looks wrong, isolate the generator: instantiate it directly against the offending class in php artisan tinker and inspect the output before hunting through Blade compilation. It's nearly always the namespace root or the prefix, not the renderer.
  • Extension point worth knowing: if you need per-module prefixes beyond what a single global name_prefix gives you, the cleanest route is usually a thin wrapper service provider in each module that calls the package's generator with an overridden config, rather than fighting the global value. Confirm against the package source whether the generator reads config statically or accepts injection — static reads will force you into config-array manipulation.
  • Deprecation risk: name_prefix is brand new in v1.0.1 and the pre-fix naming behaviour is effectively deprecated by it. Assume the implicit "derive name from namespace only" path will be removed in the next minor; don't build against it.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle