Laravel 5 how to get route action name?
To get only the method name you can use ...
$request->route()->getActionMethod()
or with a facade ...
Route::getActionMethod()
In Laravel 5 you should be using Method or Constructor injection. This will do what you want:
<?php namespace App\Http\Controllers;
use Illuminate\Routing\Route;
class HomeController extends Controller
{
public function getIndex(Route $route)
{
echo 'getIndex';
echo $route->getActionName();
}
}
To get action name, you need to use:
echo Route::getCurrentRoute()->getActionName();
and not
echo Route::getActionName();
To get action name only (without controller name):
list(, $action) = explode('@', Route::getCurrentRoute()->getActionName());