php - Laravel get view name of rendered route
971
Is here a way to achieve that : I want to check in AppServiceProvider, name of rendered view.
So, for example :
- User enters at
/home
, for that route in controller itreturn view('website.home');
- From AppServiceProvider get current route, and get view name that is rendered.
Answer
Solution:
I don't know that it's possible to get the view name in the
AppServiceProvider
, as that runs prior to a view being created in the route's respective controller method. You can get the name of the view within the controller, however, after it's been created:The current route name is accessible within the service provider using:
edit
Actually this would probably be doable with a view composer and a wildcard match on the view: