Answers for "laravel get controller name"

PHP
0

laravel get controller name

If 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:

public function boot()
{
    app('view')->composer('layouts.master', function ($view) {
        $action = app('request')->route()->getAction();

        $controller = class_basename($action['controller']);

        list($controller, $action) = explode('@', $controller);

        $view->with(compact('controller', 'action'));
    });
}
You will then have two variables available in your layout template: $controller and $action
Posted by: Guest on March-15-2021

Code answers related to "laravel get controller name"

Browse Popular Code Answers by Language