Kamlesh
Kamlesh

Reputation: 6145

How to get Controller and Action name in controller of Laravel / Lumen 8?

Is there anyone who can suggest me how can I get current URL's controller and action names in controller file in Laravel / Lumen 8 version? Thanks a lot.

Upvotes: 1

Views: 463

Answers (1)

Kamlesh
Kamlesh

Reputation: 6145

I have found the solution of it. I have used and checked in Laravel / Lumen 8 version to get controller and action name in controller:

public function getControllerActionName(){
        $this->_request = app('Illuminate\Http\Request');
        list($controllerName ,$actionName) = explode('@',$this->_request->route()[1]['uses']);
        $controllerName = strtolower(str_replace("App\Http\Controllers\\",'',$controllerName));
        $actionName = strtolower($actionName);
        return array('controller' => $controllerName, 'action' => $actionName);
    }

It worked for me. I hope, this will also help you. Happy to share.

Upvotes: 1

Related Questions