How to Get Current Route Name Path and Action in Laravel?
Teams applying “How to Get Current Route Name Path and Action in Laravel?” in a production project can use this team workflow page to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.
Before copying the example into a live application, confirm version-specific behaviour with the official Laravel website and test it against the project’s actual database and runtime.
Hello Developer,
In this short tutorial, we will cover a How to get current route name path and action in laravel. Here you will learn how to get current route name in laravel blade. you can understand a concept of how to get current route name in laravel. We will use laravel get route name. follow the below example for laravel get route name in controller.
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...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial