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
Laravel Route To Class

Laravel Route To Class Laravel Package

zschuessler/laravel-route-to-class

A small Laravel helper that resolves any route back to its controller class and method, making it easy to inspect, log, or authorize requests by their handler. Supports closures, invokable controllers, and route names with a clean, simple API.

View on GitHub
Deep Wiki
Context7

A Laravel package to easily add your own custom body classes based on routes.

Frequently asked questions about Laravel Route To Class
How do I install zschuessler/laravel-route-to-class in a Laravel app?
Install it with Composer using composer require zschuessler/laravel-route-to-class. Then publish the package config as documented and define your route-to-class mappings. The package is a small Laravel utility, so integration should mostly be config and one body-class render point in your base layout.
How do I define route-to-class mappings for body classes?
Publish the config and add mappings from route names or route patterns to one or more CSS classes. Keep the class taxonomy small and documented so frontend, analytics, and QA teams agree on naming. Start with a limited set of low-risk routes before expanding coverage.
Which Laravel and PHP versions does this package support?
The provided context does not list exact Laravel or PHP constraints, so check the package composer.json before committing. Validate it against your current Laravel and PHP versions plus your next planned upgrade target. The last release was July 2024, so confirm compatibility rather than assuming long-term support.
How do I render the route body class in a Blade layout?
Render the resolved class string in your base Blade layout's body tag, typically through the package helper or a shared view variable. Confirm that class names are sanitized and escaped correctly in your output. During rollout, compare the rendered classes against existing manual body classes before removing legacy logic.
Does it handle route parameters, wildcards, route groups, and fallback routes?
The package is designed around route identity, but route-pattern ambiguity is a known risk area for wildcards, parameters, groups, and fallbacks. Test each pattern type in a pilot and verify the resolved CSS classes match expectations. Keep mappings explicit where possible to avoid unintended CSS leakage across pages.
Can I use it with closures, invokable controllers, or named routes?
The package blurb notes support for closures, invokable controllers, and route names when resolving route identity. For body-class mappings, you will typically map route names or patterns to CSS classes. Verify closure and invokable routes in your own tests because route resolution can vary by application setup.
Is it safe to use in production and with Laravel config caching?
It introduces no database, queue, or external service dependency, so its operational footprint is low. Before production, confirm config caching behavior and middleware ordering, and test that mappings still resolve from cached config. Also check that class output is stable and does not leak across unrelated routes.
How should I test that the correct body classes are rendered?
Add feature or snapshot tests that request representative routes and assert the body class output in the rendered layout. Include parameterized, wildcard, grouped, and fallback routes so ambiguity is caught early. During the pilot, compare package output against existing manual classes before removing old styling hooks.
Does it conflict with Inertia, Livewire, or existing body-class helpers?
There is no inherent conflict if you render body classes server-side in the root Blade layout used by Inertia or Livewire. The main risk is duplicate class output or competing ownership with an existing body-class helper. Decide which system owns the route-to-class taxonomy and avoid rendering the same classes twice.
What are alternatives if I do not use this package or it is abandoned?
Alternatives include manual Blade conditionals, view composers, middleware that shares a body-class variable, or an existing design-system or feature-flag mechanism. Because the package behavior is simple, it is small enough to fork or reimplement in-house if maintenance stops. Lock-in is low, but you still need a documented class taxonomy and tests.
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.
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core