How to get current route name path and action in laravel 5

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

  1. returnRequest::route()->getName();// response productCRUD.index
  2. 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

  1. returnRoute::getCurrentRoute()->getPath();// response productCRUD
 return Route::getCurrentRoute()->getPath(); // response productCRUD



How to get current route action in Laravel

  1. returnRoute::getCurrentRoute()->getActionName();//response AppHttpControllersProductCRUDController@index
 return Route::getCurrentRoute()->getActionName(); //response AppHttpControllersProductCRUDController@index


How to get a list of all routes in Laravel?

  1. $routes=Route::getRoutes();
  2. foreach($routesas$route){
  3. echo$route->getPath().'<br>';
  4. }
 $routes = Route::getRoutes();
 foreach ($routes as $route) {
    echo $route->getPath().'<br>';
 }
Now you can easily get all registered routes, routes name and controller action in Laravel 5.

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

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  86  =  88

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US