0
0
Laravelframework~30 mins

Route naming in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Route Naming in Laravel
📖 Scenario: You are building a simple web application using Laravel. You want to create routes for your pages and give each route a unique name. This helps you refer to routes easily in your views and controllers.
🎯 Goal: Create named routes in Laravel for the home page, about page, and contact page. Use the route names to generate URLs later.
📋 What You'll Learn
Create routes for '/', '/about', and '/contact' URLs
Assign route names 'home', 'about', and 'contact' respectively
Use Laravel's Route facade and the name() method
💡 Why This Matters
🌍 Real World
Named routes help you manage URLs easily in Laravel applications, making your code cleaner and easier to maintain.
💼 Career
Understanding route naming is essential for Laravel developers to build scalable and maintainable web applications.
Progress0 / 4 steps
1
Create basic routes for pages
Create three routes using Laravel's Route::get() method for the URLs '/', '/about', and '/contact'. Each route should return a simple string response: 'Home Page', 'About Us', and 'Contact Us' respectively.
Laravel
Need a hint?

Use Route::get() with a closure that returns a string for each URL.

2
Add route names using name()
Add route names to each route using the name() method. Name the routes 'home', 'about', and 'contact' for the URLs '/', '/about', and '/contact' respectively.
Laravel
Need a hint?

Chain the name() method after each route definition to assign a name.

3
Use route names to generate URLs
Create a new route for '/links' that returns a string with URLs generated by Laravel's route() helper function using the route names 'home', 'about', and 'contact'. Return a string that lists these URLs separated by commas.
Laravel
Need a hint?

Use the route() helper inside the closure to get URLs by route names.

4
Add a route group with a name prefix
Create a route group with the name prefix 'admin.'. Inside this group, add a route for '/dashboard' that returns 'Admin Dashboard' and name it 'dashboard'. This will create a full route name 'admin.dashboard'.
Laravel
Need a hint?

Use Route::name('admin.')->group() to prefix route names inside the group.