Challenge - 5 Problems
Laravel Route Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Laravel route?
Consider this Laravel route definition:
What will a user see when they visit
Route::get('/welcome', function () { return 'Hello, Laravel!'; });What will a user see when they visit
/welcome in their browser?Laravel
Route::get('/welcome', function () { return 'Hello, Laravel!'; });
Attempts:
2 left
💡 Hint
Think about what the route returns directly to the browser.
✗ Incorrect
The route returns a simple string 'Hello, Laravel!' which Laravel sends as the HTTP response body. So the browser displays that text.
📝 Syntax
intermediate2:00remaining
Which route definition is syntactically correct?
Which of the following Laravel route definitions is valid and will not cause a syntax error?
Attempts:
2 left
💡 Hint
Look carefully at commas, parentheses, and semicolons.
✗ Incorrect
Option A has correct syntax with comma separating parameters, proper braces, and semicolon. Others miss commas, semicolons, or have mismatched parentheses.
❓ state_output
advanced2:00remaining
What is the output when visiting /user/42?
Given this Laravel route:
What will the browser display when visiting
Route::get('/user/{id}', function ($id) { return "User ID: $id"; });What will the browser display when visiting
/user/42?Laravel
Route::get('/user/{id}', function ($id) { return "User ID: $id"; });
Attempts:
2 left
💡 Hint
The {id} part is a route parameter passed to the function.
✗ Incorrect
Laravel passes the URL segment 42 as $id to the function, so it returns 'User ID: 42'.
🔧 Debug
advanced2:00remaining
Why does this route cause an error?
Look at this Laravel route:
Why will this cause an error when visiting
Route::get('/post/{id}', function () { return "Post ID: $id"; });Why will this cause an error when visiting
/post/10?Laravel
Route::get('/post/{id}', function () { return "Post ID: $id"; });
Attempts:
2 left
💡 Hint
Check if the function receives the route parameter.
✗ Incorrect
The function does not accept $id as a parameter, so $id is undefined inside it, causing an error.
🧠 Conceptual
expert3:00remaining
How many routes are defined after this code runs?
Consider this Laravel code:
How many distinct routes are registered in Laravel's router after this code executes?
Route::get('/page', fn() => 'Page');
Route::post('/page', fn() => 'Page POST');
Route::match(['get', 'post'], '/page', fn() => 'Page Match');How many distinct routes are registered in Laravel's router after this code executes?
Laravel
Route::get('/page', fn() => 'Page'); Route::post('/page', fn() => 'Page POST'); Route::match(['get', 'post'], '/page', fn() => 'Page Match');
Attempts:
2 left
💡 Hint
Think about how Laravel handles routes with same URL but different methods.
✗ Incorrect
Laravel registers routes for unique HTTP method and URI combinations, with later registrations overwriting earlier ones for the same method+URI. The first registers GET /page, the second POST /page. Route::match(['get', 'post']) registers GET /page (overwriting) and POST /page (overwriting). Thus, 2 distinct routes: GET /page and POST /page.