How to Get Current Controller Name in View Laravel?

How to Get Current Controller Name in View Laravel?

July 26, 2021 | 1 min read

If you require to get current controller name in your view file or in your middleware or your serviceprovider etc. you can get your controller details from current route like UserController, HomeController ect. you can also get full path of controller file.

you can simple get current controller name in laravel 6, laravel 7 and laravel 8 project.

In blade or view file please write the following line of code:

{{ dd(request()->route()->getAction()) }}

I'm using in views/users/index.blade.php and it's showing the following result:

array:6 [

  "middleware" => array:1 []

  "uses" => "AppHttpControllersUsersController@index"

  "controller" => "AppHttpControllersUsersController@index"

  "namespace" => null

  "prefix" => null

  "where" => []

]