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?

Beginner
A app/Http/routes.php B config/routes.php C routes/web.php D public/routes.php
Show 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?

Beginner
A GET B DELETE C PUT D POST
Show 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?

Beginner
A Route::get('/user/{id}', ...) B Route::get('/user/<id>', ...) C Route::get('/user/[id]', ...) D Route::get('/user/:id', ...)
Show 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?

Beginner
A By using the $_GET superglobal B By type-hinting the parameter in the controller method C By using the Route::input() method D By using the request() helper
Show 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?

Beginner
A Route::put() B Route::delete() C Route::post() D Route::get()
Show 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.

Beginner
A True B False
Show 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?

Intermediate
A Route::all() B Route::any() C Route::match() D Route::multiple()
Show 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?

Intermediate
A ->alias('profile') B ->label('profile') C ->name('profile') D ->as('profile')
Show 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?

Intermediate
A api B auth C guest D web
Show 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?

Intermediate
A To apply middleware to a set of routes B To define a single route for a resource C To group routes under a common prefix D To create multiple routes for a resource controller
Show 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?

Intermediate
A Route::url('admin')->group(...) B Route::path('admin')->group(...) C Route::group(['prefix' => 'admin'], ...) D Route::prefix('admin')->group(...)
Show 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?

Intermediate
A Route::get('/profile', ...)->use('auth') B Route::get('/profile', ...)->withMiddleware('auth') C Route::get('/profile', ...)->middleware('auth') D Route::get('/profile', ...)->apply('auth')
Show 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?

Intermediate
A path('profile') B url('profile') C route('profile') D link('profile')
Show 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.

Intermediate
A True B False
Show 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?

Advanced
A Route::default() B Route::missing() C Route::catchAll() D Route::fallback()
Show 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?

Advanced
A To define routes that only respond to JSON B To create routes for an API with all resource routes C To create API resource routes without 'create' and 'edit' routes D To apply API middleware to resource routes
Show 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?

Advanced
A Binding a model to a route using a custom key B Automatically injecting model instances into routes based on route parameters C Binding a route to a database table D Binding a route to a specific model class
Show 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.

Make your own

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