File tree 1 file changed +17
-1
lines changed
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Zschuessler \RouteToClass ;
4
4
5
+
5
6
use Illuminate \Support \Facades \View ;
6
7
7
8
class ServiceProvider extends \Illuminate \Support \ServiceProvider
@@ -13,7 +14,22 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider
13
14
*/
14
15
public function boot ()
15
16
{
16
- View::composer ('* ' , function ($ view ) {
17
+ View::composer ('* ' , function (\Illuminate \View \View $ view ) {
18
+ $ route = request ()->route ()->getPath ();
19
+
20
+ // Remove route parameters. product_id is removed here: `controller/product/{product_id}`
21
+ $ clean = preg_replace ("/\{([^}]+)\}/ " , '' , $ route );
22
+
23
+ // Remove characters that aren't alpha, numeric, or dashes
24
+ $ clean = preg_replace ("/[^a-zA-Z0-9\/_|+ -]/ " , '' , $ clean );
25
+
26
+ // Remove any double dashes from replace functions. eg: `product--name` should be `product-name`
27
+ $ clean = strtolower (trim ($ clean , '- ' ));
28
+
29
+ // Replace special characters with a dash
30
+ $ clean = preg_replace ("/[\/_|+ -]+/ " , '- ' , $ clean );
31
+
32
+ View::share ('route_body_classes ' , $ clean );
17
33
18
34
});
19
35
}
You can’t perform that action at this time.
0 commit comments