@@ -42,13 +42,38 @@ php artisan vendor:publish --provider="Zschuessler\RouteToClass\ServiceProvider"
42
42
43
43
** Use In Layout**
44
44
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.
46
66
47
67
Use it in any of your views like so:
48
68
49
69
``` php
50
- {{$generate_route_body_classes()}}
70
+ <?php
71
+ // This is now possible, too:
72
+ \Route2Class::addClass('test');
73
+ ?>
74
+
51
75
76
+ <body class =" {{ \Route2Class::generateClassString(); }}" ></body >
52
77
```
53
78
54
79
## Implement Your Own Rules
@@ -87,16 +112,16 @@ class UserTypeGenerator extends GeneratorAbstract
87
112
}
88
113
```
89
114
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:
91
116
92
117
```
93
118
App\Providers\RouteToClass\UserTypeGenerator::class,
94
119
```
95
120
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
97
122
see the class ` user-admin ` - ** neat** !
98
123
99
- See this file for a real-life example:
124
+ See this file for a real-life generator example:
100
125
101
126
https://github.com/zschuessler/laravel-route-to-class/blob/master/src/Generators/FullRoutePath.php
102
127
@@ -110,10 +135,10 @@ Here's an example using the default Laravel project's routes file:
110
135
``` php
111
136
Route::get('/', function () {
112
137
// Add static class as string
113
- app()['route2class']-> addClass('homepage');
138
+ Route2Class:: addClass('homepage');
114
139
115
140
// Add class from anonymous function
116
- app()['route2class']-> addClass(function() {
141
+ Route2Class:: addClass(function() {
117
142
// Your custom logic goes here
118
143
return 'my-anon-class-name';
119
144
});
0 commit comments