hi guys,
In this post,we will learn how to get the current page route name ,route path and route action name in laravel 6.you will simply get to current page route name,path and action route name.
In this post, i will tell you how can you get your current route name, route path and route action name in Laravel 6 and also you can get all registered route paths in Laravel.
Let's assume, i have created a resource route with testCRUD 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
/**
* 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 to 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 to 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 to 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();
}
}
It will help you...