What are named routes in Laravel and How can specify route names for controller actions?

+1 vote
Hii team,

What are named routes in Laravel? Does Named routes allow referring to routes when generating redirects or Urls more comfortably ?
Thank  You!!
Mar 23 in Laravel by kartik
• 27,360 points
2,759 views

1 answer to this question.

0 votes

Hey @kartik,

Named routing is another amazing feature of Laravel framework. Named routes allow referring to routes when generating redirects or Urls more comfortably.
You can specify named routes by chaining the name method onto the route definition:

Route::get('user/profile', function () {
    //
})->name('profile');

You can specify route names for controller actions:

Route::get('user/profile', 'UserController@showProfile')->name('profile');

Once you have assigned a name to your routes, you may use the route's name when generating URLs or redirects via the global route function:

// Generating URLs...
$url = route('profile');
// Generating Redirects...
return redirect()->route('profile');

Hope it helps!!

answered Mar 23 by Niroj
• 58,960 points

Related Questions In Laravel

0 votes
1 answer

.How to turn off CSRF protection for a particular route in Laravel?

Hey, We can add that particular URL or ...READ MORE

answered Mar 24 in Laravel by Niroj
• 58,960 points
747 views
0 votes
1 answer

What do you mean by Rate Limiting?How can we access control in number of routes in an application ?

Hey kartik, Laravel includes a middleware to rate ...READ MORE

answered Mar 26 in Laravel by Niroj
• 58,960 points
86 views
0 votes
1 answer

What are the important directories used in a common Laravel application

Hey @Kartik. Directories used in a common Laravel ...READ MORE

answered Mar 17 in Laravel by Niroj
• 58,960 points
97 views
0 votes
1 answer

What is the significant difference between insert() and insertGetId() function in Laravel?

Hello, Insert(): This function is simply used to ...READ MORE

answered Mar 17 in Laravel by Niroj
• 58,960 points
185 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 58,960 points
2,203 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 58,960 points
244 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 58,960 points
191 views
0 votes
1 answer

What is database migration and how to create database migration in Laravel?

Hii, Migrations are like version control for your database, ...READ MORE

answered Mar 23 in Laravel by Niroj
• 58,960 points
152 views
0 votes
1 answer

How to pass data through URL and access through controller in Laravel?

Hello, You can  first refer how to  Create controller through ...READ MORE

answered Mar 18 in Laravel by Niroj
• 58,960 points
1,773 views
0 votes
1 answer

What is middleware? How can we register middeleware in Laravel?

Middleware acts as a bridge between a ...READ MORE

answered Mar 18 in Laravel by Niroj
• 58,960 points
277 views