How to get current route name path and action in laravel 5
In this post we will give you information about How to get current route name path and action in laravel 5. Hear we will give you detail about How to get current route name path and action in laravel 5And how to use it also give you demo for it if it is necessary.
In this post, i will tell you how can you get your current route name, route path and route action name in Laravel 5 and also you can get all registered route paths in Laravel.
Let’s assume, i have created a resource route with productCRUD and navigating its index method then what will be response if i will use following methods to get information about routes.
How to get current route name in Laravel
- returnRequest::route()->getName();// response productCRUD.index
- returnRoute::currentRouteName();// response productCRUD.index
return Request::route()->getName(); // response productCRUD.index return Route::currentRouteName(); // response productCRUD.index
How to get current route path in Laravel
- returnRoute::getCurrentRoute()->getPath();// response productCRUD
return Route::getCurrentRoute()->getPath(); // response productCRUD
How to get current route action in Laravel
- returnRoute::getCurrentRoute()->getActionName();//response AppHttpControllersProductCRUDController@index
return Route::getCurrentRoute()->getActionName(); //response AppHttpControllersProductCRUDController@index
How to get a list of all routes in Laravel?
- $routes=Route::getRoutes();
- foreach($routesas$route){
- echo$route->getPath().'<br>';
- }
$routes = Route::getRoutes();
foreach ($routes as $route) {
echo $route->getPath().'<br>';
}Hope this code and post will helped you for implement How to get current route name path and action in laravel 5. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs