Trying to set a class based on my current controller or current route (URL Segment 1).
something like
<body class="{{controllerName}}">
That way in case I need to target separate pages for CSS specificity, it makes it easy.
Accessing The Current Route The Route::current() method will return the route handling the current HTTP request, allowing you to inspect the full Illuminate\Routing\Route instance: $route = Route::current(); $name = $route->getName(); $actionName = $route->getActionName();
Example 1: Get current route name in Blade Files $route = Route::current(); dd($route); $name = $route->getName(); dd($name); $actionName = $route->getActionName(); dd($actionName); $name = Route::currentRouteName(); dd($name); $action = Route::currentRouteAction(); dd($action);
All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web. php file defines routes that are for your web interface.
My solution would be: subscribe to route changes at route scope and put name of the controller there:
app.run(function($rootScope) { $rootScope.$on('$routeChangeSuccess', function(ev,data) { if (data.$route && data.$route.controller) $rootScope.controller = data.$route.controller; }) });
Check Plunker solution
You can use the $route service, it has current
property which will give you current controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With