How to Get Current Route Name in Laravel
Laravel

How to Get Current Route Name in Laravel

In this comprehensive tutorial, you'll master the art of retrieving the current route name using Laravel versions 6 through 10. Unveil multiple strategies to effortlessly fetch the route name within controllers, middleware, or blade files. Let's embark on this journey:

Get route name in Controller or Middleware

1. You can get the route name using the route facade in the controller or middleware

use Illuminate\Support\Facades\Route;



public function index(){
        $routeName = Route::currentRouteName();
	    dd($routeName);
    }

2. Using request facade to get the current route name

public function index(){
        $routeName = \Request::route()->getName();
        dd($routeName);
    }

Get the route name in Blade View

Similarly, you can also use in blade file to get the current route

{{ Route::currentRouteName() }}

Thanks for your time, hope it will help you to getting the route name in the controller, middleware or in the view where you want.

Get The latest Coding solutions.

Subscribe to the Email Newsletter