Get Current Route Name using Laravel Example

Today, We want to share with you Get Current Route Name using Laravel Example.In this post we will show you How to check current URL or Route, hear for Route::currentRouteName() returns the route name we will give you demo and example for implement.In this post, we will learn about How to get current route name path and action in laravel 5 with an example.

Get Current Route Name using Laravel Example

There are the Following The simple About Get Current Route Name using Laravel Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 5.5 Get Route Name in Controller, View and Middleware, so the php – How to get current route name in laravel 5? for this example is following below.

Example 1: Get current route name in Blade Files

Accessing The Current Route using Laravel

$route = Route::current();
dd($route);

$name = $route->getName();
dd($name);

$actionName = $route->getActionName();
dd($actionName);

$name = Route::currentRouteName();
dd($name);

$action = Route::currentRouteAction();
dd($action);

Using Request:

$route_liveName = Request::route()->getName());
print($route_liveName);

Using Route:

$route_liveName = Route::getCurrentRoute()->getPath();
print($route_liveName);

Example 2: get current route name using Laravel

return \Request::route()->getName(); 
// response membersDATA.index

return \Route::currentRouteName(); 
// response membersDATA.index

Example 3: get current route path using Laravel

 return \Route::getCurrentRoute()->getPath(); 
 // response membersDATA

Example 4: get current route action using Laravel

 return \Route::getCurrentRoute()->getActionName(); 
 //response App\Http\Controllers\[email protected]

Example 5: get a list of all routes using Laravel?

 $all_routes = \Route::getRoutes();
 foreach ($all_routes as $route) {
    echo $route->getPath().'<hr/>';
 }

Free Download Example – Pakainfo.com

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Get Current Route Name using Laravel Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   How to Get Current Route Name?
  2.   Laravel cURL Send HTTP Request Example
  3.   PHP File file_get_contents Handling Function
  4.   How to check if file exists or not in Laravel 5?
  5.   Simple PHP Create Custom Captcha Generator
  6.   jQuery Capture Webcam Image Using Web Camera in PHP
  7.   PHP warning: invalid argument supplied for foreach()
  8.   Laravel 6 Advanced Where Clauses Tutorial With Example
  9.   Laravel 6 eloquent Batch update multiple Jobs
  10.   How to pass data to all views in Laravel 5.8?