Laravel Routing: 17 MCQs with answers
All 17 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 6 questions
Q1. Which file is used to define routes in a Laravel application?
BeginnerShow answer & explanation
routes/web.php
In Laravel, web routes are defined in routes/web.php. This file is loaded by the RouteServiceProvider.
Q2. Which HTTP verb is used to retrieve a resource in Laravel routing?
BeginnerShow answer & explanation
GET
The GET method is used to request data from a specified resource. In Laravel, Route::get() defines a route that responds to GET requests.
Q3. What is the correct way to define a route parameter in Laravel?
BeginnerShow answer & explanation
Route::get('/user/{id}', ...)
Laravel uses curly braces to define route parameters, e.g., {id}.
Q4. How can you retrieve the value of a route parameter in a controller?
BeginnerShow answer & explanation
By type-hinting the parameter in the controller method
Route parameters are injected into controller methods as arguments. You can also access them via the Request object.
Q5. Which method is used to define a route that responds to a specific HTTP verb and URI?
BeginnerShow answer & explanation
Route::get()
Route::get() defines a route that responds to GET requests. Similarly, other methods exist for other verbs.
Q6. The Route::any() method allows a route to respond to all HTTP verbs.
BeginnerShow answer & explanation
True
Route::any() registers a route that responds to any HTTP verb (GET, POST, PUT, DELETE, etc.).
Building up · 8 questions
Q7. Which method is used to define a route that responds to multiple HTTP verbs?
IntermediateShow answer & explanation
Route::match()
Route::match() allows you to specify an array of HTTP verbs that the route should respond to. Route::any() responds to all verbs.
Q8. Which method is used to name a route in Laravel?
IntermediateShow answer & explanation
->name('profile')
The name() method is used to assign a name to a route, allowing you to generate URLs or redirects easily.
Q9. Which middleware is applied to routes defined in routes/web.php by default?
IntermediateShow answer & explanation
web
Routes in routes/web.php are automatically assigned the 'web' middleware group, which includes session state, CSRF protection, etc.
Q10. What is the purpose of the Route::resource() method?
IntermediateShow answer & explanation
To create multiple routes for a resource controller
Route::resource() generates all the necessary routes for a typical 'CRUD' resource controller.
Q11. Which method is used to group routes under a common URL prefix?
IntermediateShow answer & explanation
Route::prefix('admin')->group(...)
The prefix() method is used to add a prefix to all routes within a group. Alternatively, you can use the 'prefix' key in the group array.
Q12. What is the correct way to apply a middleware to a specific route?
IntermediateShow answer & explanation
Route::get('/profile', ...)->middleware('auth')
The middleware() method is used to assign middleware to a route.
Q13. Which method is used to generate a URL for a named route?
IntermediateShow answer & explanation
route('profile')
The global route() helper function generates a URL for a given named route.
Q14. Routes defined in routes/api.php are stateless and do not have session state.
IntermediateShow answer & explanation
True
API routes are stateless and do not include session state or CSRF protection, unlike web routes.
Topper level · 3 questions
Q15. Which method is used to define a fallback route in Laravel?
AdvancedShow answer & explanation
Route::fallback()
Route::fallback() defines a route that will be executed when no other route matches the incoming request.
Q16. What is the purpose of the Route::apiResource() method?
AdvancedShow answer & explanation
To create API resource routes without 'create' and 'edit' routes
Route::apiResource() excludes the 'create' and 'edit' routes, which are not needed for APIs.
Q17. What is route model binding in Laravel?
AdvancedShow answer & explanation
Automatically injecting model instances into routes based on route parameters
Route model binding automatically resolves Eloquent models from route parameters. For example, {user} will inject the User model with matching ID.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages