laravel get controller name

Solutions on MaxInterview for laravel get controller name by the best coders in the world

showing results for - "laravel get controller name"
Cyrielle
24 May 2019
1If your layout is a Blade template, you could create a view composer that injects those variables into your layout. In app/Providers/AppServiceProvider.php add something like this:
2
3public function boot()
4{
5    app('view')->composer('layouts.master', function ($view) {
6        $action = app('request')->route()->getAction();
7
8        $controller = class_basename($action['controller']);
9
10        list($controller, $action) = explode('@', $controller);
11
12        $view->with(compact('controller', 'action'));
13    });
14}
15You will then have two variables available in your layout template: $controller and $action