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.
JavaScript
x
<?php namespace AppHttpControllers;
use Route;
class HomeController extends Controller
{
public function getIndex()
{
echo 'getIndex';
echo Route::getActionName();
}
}
Advertisement
Answer
In Laravel 5 you should be using Method or Constructor injection. This will do what you want:
JavaScript
<?php namespace AppHttpControllers;
use IlluminateRoutingRoute;
class HomeController extends Controller
{
public function getIndex(Route $route)
{
echo 'getIndex';
echo $route->getActionName();
}
}