HDTuto.com

Laravel 5.5 Get Route Name in Controller, View and Middleware


Hi, Guys

Today is crazy day, I want to let you know how to get route name in controller or view or middleware etc in your laravel 5.5 application. Sometime, we need to get route name for as per give on url.

We can easily get route name two way using following facade:

1) Request:

2) Route:

If you are getting route name in controller then "Request" facade will help to get route name.

If you want to get route name in view file or anywhere then you can simply use "Route" facade.

Here i will show you Request and Route facade example to how we can get route name in laravel 5 app.

Get Route Name using Request:

public function mySearch()

{

$routeName = Request::route()->getName());

dd($routeName);

}

Get Route Name using Route:

public function mySearch()

{

$routeName = Route::currentRouteName();

dd($routeName);

}

As you can see above both example, how is it easy. So try this way.

I hope you found best solution....




November 7, 2017 | Category : PHP Laravel Laravel 5 Laravel 5.5
Related Posts