How to Get Current Route Name in Laravel

In this tutorial, you can learn, how to get the current route name using laravel. There are a few ways to get the route name in the controller, middleware, or blade file. So, let's start:

 

Get route name in Controller or Middleware

1. You can get the route name using the route facade in 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 route name in Blade View

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

{ Route::currentRouteName() }}
Tags : laravel PHP

Related Post