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....
Do you like below Tutorials ?
- Laravel 5.6 - Collection could not be converted to int
- Laravel - How to generate secure https URL from route?
- Laravel - Vue JS File Upload Example
- How to get last 7 days data in Laravel?
- Laravel Validation required if other field empty example
- Laravel Eloquent - When Case Statement in Select Query Example
- Laravel 7.x and 6.x Passing Variable to Javascript Example
- How to pass PHP variables in JavaScript or jQuery?