How to get the name of the requested controller and actions in the Laravel middleware

I am new to Laravel and I want to get the name of the requested controller and action in the revision tool.

Thanks DJ

+6
source share
1 answer

You can get the current action name using Route::currentRouteAction() . Unfortunately, this method will return the full name of the class with the names. So you get something like:

 App\Http\Controllers\ FooBarController@method 

Then just highlight the method name and controller name:

 $currentAction = \Route::currentRouteAction(); list($controller, $method) = explode('@', $currentAction); // $controller now is "App\Http\Controllers\FooBarController" $controller = preg_replace('/.*\\\/', '', $controller); // $controller now is "FooBarController" 
+12
source

Source: https://habr.com/ru/post/987875/


All Articles