0
0
Laravelframework~30 mins

Route prefixes in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Route prefixes
📖 Scenario: You are building a simple web application with Laravel. You want to organize your routes by grouping them under a common URL prefix to keep your code clean and easy to manage.
🎯 Goal: Create a route group with the prefix admin and define two routes inside it: one for /dashboard and one for /settings. Each route should return a simple string response.
📋 What You'll Learn
Create a route group with the prefix admin
Inside the group, define a GET route for /dashboard that returns the string 'Admin Dashboard'
Inside the group, define a GET route for /settings that returns the string 'Admin Settings'
💡 Why This Matters
🌍 Real World
Route prefixes help organize URLs in web applications, making it easier to manage related routes like admin pages.
💼 Career
Understanding route groups and prefixes is essential for Laravel developers to write clean, maintainable routing code.
Progress0 / 4 steps
1
Create the initial routes
Create two GET routes outside any group: one for /dashboard that returns 'Dashboard' and one for /settings that returns 'Settings'.
Laravel
Need a hint?

Use Route::get() with the URL and a closure that returns the string.

2
Add the route prefix group
Create a route group with the prefix admin using Route::prefix('admin')->group(function () { ... }); and move the two routes inside this group.
Laravel
Need a hint?

Wrap the routes inside Route::prefix('admin')->group(function () { ... });.

3
Change route responses to indicate admin area
Inside the admin prefix group, change the /dashboard route to return 'Admin Dashboard' and the /settings route to return 'Admin Settings'.
Laravel
Need a hint?

Update the return strings inside each route closure.

4
Add a named route inside the prefix group
Inside the admin prefix group, add a new GET route for /profile that returns 'Admin Profile' and name this route admin.profile using ->name('admin.profile').
Laravel
Need a hint?

Use Route::get('/profile', function () { ... })->name('admin.profile'); inside the group.