___andrewk___'s avatar

get controller name when called using App::call

in my routes i call some controller dynamically for ajax:

//procession all ajax requests
    Route::any('ajax/{controller}/{function}', function($controller,$function) {
        return App::call('App\Http\Controllers\' . str_replace('.','\',$controller) . '@' . $function);
    });

i also use middleware to check for access permissions for each controller:

$currentAction = \Route::currentRouteAction();

it works perfect for statically stated routes, but for App:call it returns null. any suggestion on a workaround? is there a better way to get a name of the controller in the middleware?

0 likes
2 replies
___andrewk___'s avatar

if anyone is facing a similar problem:

$controller = $request->route()->parameters['controller'];

allows you to get url parameters as a workaround

1 like
kamleshcgtechno's avatar

Any suggestion for getting controller and action name Laravel / Lumen version 8 ? Thanks

Please or to participate in this conversation.