PHPackages                             zschuessler/laravel-route-to-class - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. zschuessler/laravel-route-to-class

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

zschuessler/laravel-route-to-class
==================================

A Laravel view composer that will convert the current route to a body class. 'admin/product/5/edit' becomes 'admin-product-edit'

2.13.0(1y ago)26428.8k↓11.9%12[2 PRs](https://github.com/zschuessler/laravel-route-to-class/pulls)1NLPLPHP

Since Dec 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/zschuessler/laravel-route-to-class)[ Packagist](https://packagist.org/packages/zschuessler/laravel-route-to-class)[ RSS](/packages/zschuessler-laravel-route-to-class/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (23)Used By (1)

[![Alt text](https://raw.githubusercontent.com/zschuessler/laravel-route-to-class/master/readme-screenshot.png "Screenshot")](https://raw.githubusercontent.com/zschuessler/laravel-route-to-class/master/readme-screenshot.png)

Dynamic Body Classes for Laravel
================================

[](#dynamic-body-classes-for-laravel)

Quickly add body classes to your Laravel app based on rules you set.

Example of implementations:

1. Browsing as a guest might add `user-isGuest` as a class.
2. Browsing an admin panel might add `admin-panel` as a class.
3. All user profile routes might have `user-profile` as a class.

It's easy to write your own rules! You can either write your own generator classes or use the ad-hoc API by interacting with the library singleton directly.

Quickstart
----------

[](#quickstart)

**Require the package in your composer setup.**

```
composer require zschuessler/laravel-route-to-class

```

**Publish the configuration file**

Run the following command in the root directory of your project:

```
php artisan vendor:publish --provider="Zschuessler\RouteToClass\ServiceProvider"
```

**Use In Layout**

You can either use the included Blade directive, or access the Route2Class facade directly for outputting your classes.

*Blade*

Two important notes for using the Blade directive:

1. The Blade directive will follow any caching solutions you have setup. This is great for production, but keep in mind on development you may be viewing cached classes when modifying generators.
2. The Blade directive runs before all other view template code. As such, any calls to the Route2Class package in a view will not show up in your class list.

```

```

*Facade*

Facades are not cached in the manner Blade directives are, making them great for development environments. And because we aren't using a Blade directive, you can modify classes and generators within view templates too.

Use it in any of your views like so:

```
