@@ -42,13 +42,38 @@ php artisan vendor:publish --provider="Zschuessler\RouteToClass\ServiceProvider"
4242
4343** Use In Layout**
4444
45- You now have access to a shared view variable function ` $generate_route_body_classes ` .
45+ You can either use the included Blade directive, or access the Route2Class facade directly for
46+ outputting your classes.
47+
48+ * Blade*
49+
50+ Two important notes for using the Blade directive:
51+
52+ 1 . The Blade directive will follow any caching solutions you have setup. This is great for production, but keep in mind
53+ on development you may be viewing cached classes when modifying generators.
54+ 2 . The Blade directive runs before all other view template code. As such, any calls to the Route2Class
55+ package in a view will not show up in your class list.
56+
57+ ``` php
58+ <body class =" @route2class_generate_classes" ></body >
59+ ```
60+
61+ * Facade*
62+
63+ Facades are not cached in the manner Blade directives are, making them great for development
64+ environments. And because we aren't using a Blade directive, you can modify classes and generators
65+ within view templates too.
4666
4767Use it in any of your views like so:
4868
4969``` php
50- {{$generate_route_body_classes()}}
70+ <?php
71+ // This is now possible, too:
72+ \Route2Class::addClass('test');
73+ ?>
74+
5175
76+ <body class =" {{ \Route2Class::generateClassString(); }}" ></body >
5277```
5378
5479## Implement Your Own Rules
@@ -87,16 +112,16 @@ class UserTypeGenerator extends GeneratorAbstract
87112}
88113```
89114
90- Now add a reference to the generator in your ` /config/route2class.php ` configuration:
115+ Next add a reference to the generator in your ` /config/route2class.php ` configuration:
91116
92117```
93118App\Providers\RouteToClass\UserTypeGenerator::class,
94119```
95120
96- Now when you use the ` {{$generate_route_to_classes()}} ` line in a view template, you will
121+ Now when you call the facade or Blade directive in a view template, you will
97122see the class ` user-admin ` - ** neat** !
98123
99- See this file for a real-life example:
124+ See this file for a real-life generator example:
100125
101126https://github.com/zschuessler/laravel-route-to-class/blob/master/src/Generators/FullRoutePath.php
102127
@@ -110,10 +135,10 @@ Here's an example using the default Laravel project's routes file:
110135 ``` php
111136Route::get('/', function () {
112137 // Add static class as string
113- app()['route2class']-> addClass('homepage');
138+ Route2Class:: addClass('homepage');
114139
115140 // Add class from anonymous function
116- app()['route2class']-> addClass(function() {
141+ Route2Class:: addClass(function() {
117142 // Your custom logic goes here
118143 return 'my-anon-class-name';
119144 });
0 commit comments