0
0
Laravelframework~20 mins

Basic route definition in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Laravel Route Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Laravel route?
Consider this Laravel route definition:
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!'; });
AA 404 Not Found error page
BA blank page with no content
CA JSON response with {"message": "Hello, Laravel!"}
DThe text 'Hello, Laravel!' displayed in the browser
Attempts:
2 left
💡 Hint
Think about what the route returns directly to the browser.
📝 Syntax
intermediate
2:00remaining
Which route definition is syntactically correct?
Which of the following Laravel route definitions is valid and will not cause a syntax error?
ARoute::get('/home', function() { return 'Home'; });
BRoute::get('/home' function() { return 'Home'; });
CRoute::get('/home', function() { return 'Home' });
DRoute::get('/home', function() { return 'Home'; )
Attempts:
2 left
💡 Hint
Look carefully at commas, parentheses, and semicolons.
state_output
advanced
2:00remaining
What is the output when visiting /user/42?
Given this Laravel route:
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"; });
A404 Not Found error
BUser ID: {id}
CUser ID: 42
DUser ID: $id
Attempts:
2 left
💡 Hint
The {id} part is a route parameter passed to the function.
🔧 Debug
advanced
2:00remaining
Why does this route cause an error?
Look at this Laravel route:
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"; });
ABecause the function must return a view, not a string
BBecause $id is not passed as a parameter to the function
CBecause the route method get() is not valid
DBecause the route URL is missing a leading slash
Attempts:
2 left
💡 Hint
Check if the function receives the route parameter.
🧠 Conceptual
expert
3:00remaining
How many routes are defined after this code runs?
Consider this Laravel code:
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');
A2
B1
C4
D3
Attempts:
2 left
💡 Hint
Think about how Laravel handles routes with same URL but different methods.