File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 22
33namespace Zschuessler \RouteToClass ;
44
5+
56use Illuminate \Support \Facades \View ;
67
78class ServiceProvider extends \Illuminate \Support \ServiceProvider
@@ -13,7 +14,22 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider
1314 */
1415 public function boot ()
1516 {
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 );
1733
1834 });
1935 }
You can’t perform that action at this time.
0 commit comments