How To Get Route Name In Controller Laravel 6?
Dec 03, 2019
Hi Developer,
In this tutorial,i will tell you how can you get your current route name in Laravel 6. we will present route name in controller and view file in laravel 6, it can get current route then "Route" facade of currentRouteName function.i can get current route name laravel 6 so the do the following example.
I can blow you can easily get current route name in this example.
Route
Route::get('home', 'HomeController@index')->name('home');
Example:1
If you are getting route name in controller then "Request" facade will help to get route name.
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$routeName = Request::route()->getName();
dd($routeName);
}
Output:
home
Example:2
If you want to get route name in view file or anywhere then you can simply use "Route" facade in currentRouteName function.
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$routeName = Route::currentRouteName();
dd($routeName);
}
Output:
home
Example:3
If you want to get route name in view file or anywhere then you can simply use "Route" facade in current function object
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$routeName = Route::current();
dd($routeName->action['as']);
}
Output:
home
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial