0

I have some theme in laravel that boot via this in my Custom package

 $this->app->makeWith( $themeClass, [ $this->app ] )

How I can get current controller name? I need this for know if this page is post or product and get id this product

in view works fine this code

            $routeArray = app( 'request' )->route()->getAction();
            $controllerAction = class_basename( $routeArray['controller'] );

but in theme not works

Call to a member function getAction() on null

I use laravel 5.6

1 Answers1

0

you can get controller name using below code

$routeArray = app('request')->route()->getAction();
$controllerAction = class_basename($routeArray['controller']);
list($controller, $action) = explode('@', $controllerAction);

$controller = $routeArray['as'];
echo $controller;exit;

in $routeArray have all controller,method, as name etc so you can easily get value you want.

Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39