How to get current route in laravel ?

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

hello dev’s, Today now in this post,i will teach you about how to get the current page route name ,route path and also route action name in laravel application. So we will simply get to current page route name,path and action route name in laravel application. i will show you How to get current route in laravel ?

Now from this post, i will tell you about how can you get our current route name, route path and also route action name in Laravel 8 application and also we can get all registered route paths in Laravel application.

Let’s assume, we have to created a resource route with  test CRUD and navigating its index method. Then know what will be response if we will use following methods to get information about our routes.

How can we get current route name in Laravel

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
     $routes = \Request::route()->getName();

     dd($routes);
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
     $routes = \Route::currentRouteName();

     dd($routes);
}

How can we get current route path in Laravel

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
     $routes = \Route::getCurrentRoute()->getPath();

     dd($routes);
}

How can we get current route action in Laravel

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
     $routes = \Route::getCurrentRoute()->getActionName();

     dd($routes);
}

How can we get a list of all routes in Laravel

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
     $routes = \Route::getRoutes();

     foreach ($routes as $route) {

    	echo $route->getPath();

 	 }
}

Read Also : How to get current URL with parameters in Laravel ?

Thanks for read. I hope it help you. For more you can follow us on facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →