panthro
panthro

Reputation: 24059

Get the action name in Laravel

I need to get the action name in laravel:

mysite.com/manager/user-list

So in the above example I want 'user-list'

I know you can get the current route name by:

Route::currentRouteName();

But this is no good to me, I need this to stay as 'manager' for other reasons.

Upvotes: 0

Views: 3031

Answers (3)

user3123137
user3123137

Reputation: 51

https://laravel.com/docs/5.3/routing#accessing-the-current-route

The link above shows you how to solve your problem:

$action = Route::currentRouteAction();

Upvotes: 1

itachi
itachi

Reputation: 6393

i don't know what you are trying to do but this is one of the methods to get the action.

print_r(explode('@',Route::currentRouteAction()));

Output

Array ( [0] => HomeController [1] => index )

so 1st element will hold the controller (provided not namespaced, otherwise you will have to remove the namespace part manuelly) and 2nd element will hold the action.

your question and the explanation doesn't match.

if you want the action, this is one of the process.

but i think, Andreyco's answer gives you what you need. i just put it for future reference if someone finds it helpful.

Upvotes: 1

Andreyco
Andreyco

Reputation: 22872

If you want to get URL segment (not controller action), you can call segment method on Request Facade.

Request::segment(2);

Upvotes: 2

Related Questions