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(); } }
Example 1: Get current route name in Blade Files $route = Route::current(); dd($route); $name = $route->getName(); dd($name); $actionName = $route->getActionName(); dd($actionName); $name = Route::currentRouteName(); dd($name); $action = Route::currentRouteAction(); dd($action);
Named RoutesNamed routes allow the convenient generation of URLs or redirects for specific routes. You may specify a name for a route by chaining the name method onto the route definition: Route::get('/user/profile', function () {
To get action name, you need to use:
echo Route::getCurrentRoute()->getActionName();
and not
echo Route::getActionName();
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(); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With