laravel basic exmaple: 18 MCQs with answers
All 18 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 6 questions
Q1. Which file does every incoming Laravel request pass through first?
BeginnerShow answer & explanation
`public/index.php`
The request enters through `public/index.php`, which bootstraps the framework and hands the request to the router. Routes, controllers, and views are reached later in the pipeline.
Q2. In which file are web routes defined?
BeginnerShow answer & explanation
`routes/web.php`
Web routes live in `routes/web.php`, where URLs and HTTP verbs are mapped to closures or controller methods.
Q3. What does the Blade syntax `{{ $name }}` do?
BeginnerShow answer & explanation
Outputs the value of `$name`
Double curly braces are Blade's output syntax. They echo the value of the variable, escaped for safety. Control flow uses directives like `@if` and `@foreach`.
Q4. Which Artisan command applies pending migrations to the database?
BeginnerShow answer & explanation
`php artisan migrate`
`php artisan migrate` runs all pending migrations. `make:migration` only creates the migration file; it does not apply it.
Q5. A developer writes a route that returns a plain string with no controller and no view. What is this route best suited for?
BeginnerShow answer & explanation
A tiny demo or quick test
Closure routes that return a string are the absolute minimum working example. They suit tiny demos and quick checks; real features move logic into controllers.
Q6. Laravel follows the MVC pattern, separating routes, controllers, models, and views into distinct layers.
BeginnerShow answer & explanation
True
Laravel follows the MVC pattern, separating routes, controllers, models, and views into distinct layers.
Building up · 7 questions
Q7. A controller method needs to send a variable into a Blade view. Which call does this correctly?
IntermediateShow answer & explanation
`return view('hello', ['name' => 'Veda']);`
The `view()` helper takes the template name and an array of data. The array keys become variables available inside the Blade template.
Q8. Why does Laravel separate routes, controllers, and views into different layers?
IntermediateShow answer & explanation
So each layer holds one responsibility and stays readable
Routes map URLs to actions, controllers hold logic, and views hold presentation. Keeping each layer to one job is the habit a basic example teaches; mixing them breaks down as the app grows.
Q9. A learner puts a database query directly inside a Blade template. Why is this considered a mistake?
IntermediateShow answer & explanation
Views should hold presentation, not data logic
Blade compiles to plain PHP, so a query technically runs — but views are for presentation. Data fetching belongs in the controller or model, keeping each layer to one responsibility.
Q10. What does `Post::all()` return in a basic Laravel example?
IntermediateShow answer & explanation
A collection of all rows from the `posts` table
`Post::all()` fetches every row from the `posts` table as a collection of `Post` model instances, ready to be passed to a view.
Q11. A team clones a Laravel project and needs the same database structure on a new machine. What makes this reproducible?
IntermediateShow answer & explanation
Migrations, applied with `php artisan migrate`
Migrations are version-controlled PHP files defining table structure. Running `php artisan migrate` recreates the database with one command, avoiding manual SQL and drift between machines.
Q12. Which statement correctly describes the role of `php artisan make:controller`?
IntermediateShow answer & explanation
It scaffolds a controller file with boilerplate to fill in
Artisan's `make:` commands generate boilerplate files. They do not register routes, create tables, or compile views — you still write the logic and wire the route yourself.
Q13. A controller action must show only published posts. Which Eloquent call expresses this most clearly?
IntermediateShow answer & explanation
`Post::where('published', true)->get()`
Eloquent's query builder chains `where()` with `get()`, reading almost like English while hiding raw SQL. The other calls are not valid Eloquent query methods.
Topper level · 5 questions
Q14. A basic example starts with a closure route and is later refactored into a controller route. What does this progression best illustrate?
AdvancedShow answer & explanation
Why Laravel separates concerns as features grow
Closure routes are fine for tiny demos, but as logic grows, controllers keep routes readable and logic testable and reusable. The refactor itself demonstrates the value of separation of concerns.
Q15. A developer needs a route that is easy to unit test and reused by three different URLs. Which choice fits best?
AdvancedShow answer & explanation
A controller method referenced by each route
Controllers group logic into testable methods and let multiple routes point at the same action. Copied closures duplicate logic, and views should never decide routing.
Q16. A learner claims a basic Laravel example is 'just a toy' and shares nothing with a production app. Why is this reasoning flawed?
AdvancedShow answer & explanation
Production apps are the same loop scaled up
Every large Laravel app begins as a basic example: one route, one controller, one view, one model. The request-to-response loop, MVC separation, and Artisan workflow stay identical — only the scale changes.
Q17. Given the following Laravel code snippet, identify the correct sequence of operations that occur when a request is made to the '/hello' route: ```php Route::get('/hello', [HelloController::class, 'index']); ``` What happens after the request is received?
AdvancedShow answer & explanation
The request is routed to the HelloController, which processes the logic and returns a view.
The correct option is true because the request to '/hello' is routed to the `HelloController`, which processes the request and returns a view. This illustrates the MVC structure where the controller is responsible for handling the request logic.
Q18. Consider the following migration command and its purpose: ```bash php artisan make:migration create_posts_table ``` What is the significance of running this command in the context of a basic Laravel example, and what subsequent command is necessary to apply the migration?
AdvancedShow answer & explanation
It defines the structure of the 'posts' table, and you must run 'php artisan migrate' to apply it.
The correct option is true because running the migration command creates a migration file that defines the structure of the 'posts' table. To actually create the table in the database, you must run 'php artisan migrate', which applies the migration.
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