Recall & Review
beginner
What is a route group in Laravel?
A route group lets you share common attributes like middleware, prefix, or namespace across multiple routes to keep your code clean and organized.
Click to reveal answer
beginner
How do you add a URL prefix to all routes in a group?
Use the 'prefix' key in the group array. For example: Route::prefix('admin')->group(function () { ... }); adds 'admin/' before all routes inside.
Click to reveal answer
intermediate
What is the benefit of applying middleware in a route group?
Applying middleware in a group means all routes inside share the same middleware, so you don't repeat middleware on each route individually.
Click to reveal answer
intermediate
Show a simple example of a route group with a prefix and middleware.
Route::middleware('auth')->prefix('dashboard')->group(function () {
Route::get('/stats', [StatsController::class, 'index']);
Route::get('/profile', [ProfileController::class, 'show']);
});
This groups routes under '/dashboard' and applies 'auth' middleware.
Click to reveal answer
advanced
Can route groups be nested in Laravel? What is the use?
Yes, route groups can be nested. This helps combine multiple shared attributes like prefix and middleware in layers, making complex route structures easier to manage.
Click to reveal answer
Which of the following is NOT a common attribute you can share in a Laravel route group?
✗ Incorrect
Controller methods are defined per route, not shared in route groups. Middleware, prefix, and namespace can be shared.
How do you start a route group with a middleware named 'auth'?
✗ Incorrect
Both ways are valid to apply middleware 'auth' to a route group.
What will be the full URL for this route inside a group with prefix 'admin'?
Route::get('/users', ...);
✗ Incorrect
The prefix 'admin' is added before the route path, so the full URL is '/admin/users'.
Can you nest route groups in Laravel?
✗ Incorrect
Nesting route groups is allowed and useful to combine different shared attributes like prefix and middleware.
Which method is used to define a route group in Laravel?
✗ Incorrect
The correct method to define a route group is Route::group().
Explain how route groups help organize routes in Laravel and give an example with a prefix and middleware.
Think about how you can avoid repeating code for multiple routes.
You got /4 concepts.
Describe nesting route groups and why it might be useful in a Laravel application.
Consider when you want to apply multiple layers of prefixes or middleware.
You got /3 concepts.