0
0
Laravelframework~20 mins

Route groups in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Laravel Route Groups Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the URL prefix for routes inside this group?
Consider this Laravel route group:
Route::prefix('admin')->group(function () {
Route::get('/dashboard', function () {
return 'Admin Dashboard';
});
});

What URL path will you visit to see the 'Admin Dashboard'?
Laravel
Route::prefix('admin')->group(function () {
    Route::get('/dashboard', function () {
        return 'Admin Dashboard';
    });
});
A/admin/dashboard
B/dashboard/admin
C/admin
D/dashboard
Attempts:
2 left
💡 Hint
Think about how the prefix adds to the route path.
📝 Syntax
intermediate
2:00remaining
Which option correctly applies middleware to a route group?
You want to apply the 'auth' middleware to all routes inside a group. Which code snippet is correct?
A
Route::group(['middleware' => 'auth'], function () {
    Route::get('/profile', function () {
        return 'Profile';
    });
});
B
Route::group('middleware' => 'auth', function () {
    Route::get('/profile', function () {
        return 'Profile';
    });
});
C
Route::middleware('auth')->group(function () {
    Route::get('/profile', function () {
        return 'Profile';
    });
});
D
Route::middleware(['auth'])->group(function () {
    Route::get('/profile', function () {
        return 'Profile';
    });
});
Attempts:
2 left
💡 Hint
Check the correct syntax for passing middleware in a group.
state_output
advanced
2:00remaining
What is the output of this nested route group?
Given this Laravel route group code:
Route::prefix('api')->group(function () {
    Route::prefix('v1')->group(function () {
        Route::get('/users', function () {
            return 'Users v1';
        });
    });
});

What URL path will return 'Users v1'?
Laravel
Route::prefix('api')->group(function () {
    Route::prefix('v1')->group(function () {
        Route::get('/users', function () {
            return 'Users v1';
        });
    });
});
A/users/api/v1
B/v1/api/users
C/api/users/v1
D/api/v1/users
Attempts:
2 left
💡 Hint
Prefixes stack in the order they are nested.
🔧 Debug
advanced
2:00remaining
Why does this route group cause a syntax error?
Look at this code:
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function () {
    Route::get('/dashboard', function () {
        return 'Dashboard';
    });
});

Why does this code cause a syntax error?
Laravel
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function () {
    Route::get('/dashboard', function () {
        return 'Dashboard';
    });
});
AThe callback function is missing the use keyword to import variables.
BThe function keyword is missing parentheses after it.
CThe array syntax is correct; no syntax error here.
DThe array keys should be strings without quotes.
Attempts:
2 left
💡 Hint
Check the array syntax and function declaration carefully.
🧠 Conceptual
expert
3:00remaining
How does the 'as' option affect route names in groups?
Consider this route group:
Route::name('admin.')->group(function () {
    Route::get('/users', function () {
        return 'Users';
    })->name('users');
});

What is the full route name for the '/users' route?
Laravel
Route::name('admin.')->group(function () {
    Route::get('/users', function () {
        return 'Users';
    })->name('users');
});
Ausers
Badmin.users
Cadminusers
Dadmin.users.users
Attempts:
2 left
💡 Hint
The 'name' prefix adds before the route's own name.