I'm trying to get the current route action, but I'm not sure how to go about it. In Laravel 4 I was using Route::currentRouteAction()
but now it's a bit different.
I'm trying to do Route::getActionName()
in my controller but it keeps giving me method not found.
<?php namespace App\Http\Controllers;
use Route;
class HomeController extends Controller
{
public function getIndex()
{
echo 'getIndex';
echo Route::getActionName();
}
}
For Laravel 5.1 use:
There are lots of useful methods in this class. Just check the code for more details.
To get only action name in Laravel 5.4
explode('@', Route::getCurrentRoute()->getActionName())[1]
Can't find any better way, to use in view, in one line...
In Laravel 5 you should be using Method or Constructor injection. This will do what you want:
To get action name, you need to use:
and not
To get only the method name you can use ...
or with a facade ...
To get action name only (without controller name):