0
0
Laravelframework~20 mins

Route naming in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Laravel Route Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the URL generated by this named route?
Given the following Laravel route definition, what URL will be generated by calling route('profile.show', ['id' => 5])?
Laravel
Route::get('/user/{id}', function ($id) {
    return "User $id profile";
})->name('profile.show');
A/profile/show/5
B/profile/5
C/user?id=5
D/user/5
Attempts:
2 left
💡 Hint
Look at the route URL pattern and how parameters are passed in named routes.
📝 Syntax
intermediate
2:00remaining
Which option correctly names a route in Laravel?
Select the correct syntax to assign the name 'dashboard.home' to a route that responds to GET requests at '/dashboard'.
ARoute::get('/dashboard', function () {}, 'dashboard.home');
BRoute::get('/dashboard', function () {})->name('dashboard.home');
CRoute::name('dashboard.home')->get('/dashboard', function () {});
DRoute::get('/dashboard', function () {})->setName('dashboard.home');
Attempts:
2 left
💡 Hint
Check the Laravel documentation for the method used to name routes.
state_output
advanced
2:00remaining
What is the output of this route helper call?
Consider this route group with a name prefix. What is the output of route('admin.users.index')?
Laravel
Route::name('admin.')->group(function () {
    Route::get('/users', function () {
        return 'Users list';
    })->name('users.index');
});
A/users
B/admin/users
C/admin.users.index
D/users.index
Attempts:
2 left
💡 Hint
Name prefixes affect route names, not URLs.
🔧 Debug
advanced
2:00remaining
Why does this named route call cause an error?
Given this route definition, why does calling route('product.show') cause an error?
Laravel
Route::get('/product/{id}', function ($id) {
    return "Product $id";
})->name('product.show');
ABecause the route callback function does not return a view.
BBecause the route name 'product.show' is invalid and cannot be used.
CBecause the route requires a parameter 'id' which was not provided in the route() call.
DBecause the route URL '/product/{id}' is missing a trailing slash.
Attempts:
2 left
💡 Hint
Check if all required parameters are passed when generating URLs.
🧠 Conceptual
expert
3:00remaining
How does Laravel resolve route names with nested groups?
Given nested route groups with name prefixes, what is the full route name for the inner route?
Laravel
Route::name('api.')->group(function () {
    Route::name('v1.')->group(function () {
        Route::get('/items', function () {
            return 'Items list';
        })->name('items.index');
    });
});
Aapi.v1.items.index
Bv1.api.items.index
Citems.index
Dapi.items.index
Attempts:
2 left
💡 Hint
Name prefixes concatenate in the order of nesting.