0
0
Laravelframework~30 mins

Route groups in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Organizing Routes with Route Groups in Laravel
📖 Scenario: You are building a simple web application with Laravel. You want to organize your routes by grouping them under a common URL prefix and middleware for better structure and security.
🎯 Goal: Create a route group in Laravel that applies a URL prefix /admin and middleware auth to three routes: /dashboard, /users, and /settings.
📋 What You'll Learn
Create a route group with prefix admin
Apply middleware auth to the route group
Define three GET routes inside the group: /dashboard, /users, and /settings
Each route should return a simple string response indicating the page name
💡 Why This Matters
🌍 Real World
Route groups help keep Laravel routes organized and secure by applying common settings to many routes at once.
💼 Career
Understanding route groups is essential for Laravel developers to build scalable and maintainable web applications.
Progress0 / 4 steps
1
Set up the initial routes without grouping
Create three GET routes in routes/web.php for /admin/dashboard, /admin/users, and /admin/settings. Each route should return a string: "Dashboard Page", "Users Page", and "Settings Page" respectively.
Laravel
Need a hint?

Use Route::get() for each URL with a closure returning the page name string.

2
Create a route group with prefix and middleware
Create a route group using Route::prefix('admin')->middleware('auth')->group() and place the three routes inside this group. Remove the /admin prefix from individual routes inside the group.
Laravel
Need a hint?

Use Route::prefix('admin')->middleware('auth')->group(function () { ... }); and put the routes inside the function.

3
Add a name prefix to the route group
Add a name prefix admin. to the route group by chaining ->name('admin.') to the group definition. This will prefix route names inside the group.
Laravel
Need a hint?

Chain ->name('admin.') before ->group() to add the name prefix.

4
Name each route inside the group
Add route names to each route inside the group using ->name() with these exact names: dashboard, users, and settings.
Laravel
Need a hint?

Use ->name('dashboard'), ->name('users'), and ->name('settings') after each route definition.