---
title: "PHP & Laravel: Modern Web Development Fundamentals"
description: "Test your knowledge of PHP and Laravel covering routing, Eloquent ORM, Blade templates, middleware, migrations, and the artisan workflow."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/quizzes/post/php-laravel-fundamentals-quiz
---

# PHP & Laravel: Modern Web Development Fundamentals

Ready to check how well you know PHP and Laravel? This quiz runs through routing and middleware, Eloquent relationships and the N+1 trap, migrations and seeders, Blade, and the artisan workflow. Read the explanations. That is where the learning happens.

## Questions

### 1. In Laravel, where do you typically define web routes?

- routes/web.php
- app/Http/routes.php
- config/routes.php
- public/index.php

**Hint:** It is under the routes directory, for browser-facing pages.

### 2. What does route model binding do?

- It automatically injects the model instance matching a route parameter, resolving it from the database.
- It binds a route to a specific HTTP method.
- It caches route definitions for performance.
- It generates a URL from a model.

**Hint:** Type-hint a model in the controller and Laravel finds it for you.

### 3. What is Eloquent?

- Laravel's ORM that maps database tables to model classes.
- Laravel's templating engine.
- Laravel's routing layer.
- Laravel's queue system.

**Hint:** It is how you talk to the database with objects.

### 4. What is the N+1 query problem in Eloquent?

- Loading a list and then lazily querying a relationship for each item, causing one query plus N more.
- Running the same migration N times.
- Having N+1 columns in a table.
- A caching bug that duplicates rows.

**Hint:** It is why you reach for with() / eager loading.

### 5. How do you eager load a relationship to avoid N+1?

- Model::with(\"comments\")->get()
- Model::lazy(\"comments\")->get()
- Model::join(\"comments\")->get()
- Model::cache(\"comments\")->get()

**Hint:** The method name describes loading a relationship along with the model.

### 6. What does a database migration let you do?

- Define and version schema changes in code so they can be applied and rolled back consistently.
- Move data between two servers.
- Convert a MySQL database to PostgreSQL automatically.
- Seed the database with fake data.

**Hint:** Think version control, but for your database schema.

### 7. Which artisan command runs pending migrations?

- php artisan migrate
- php artisan db:push
- php artisan schema:update
- php artisan migrate:make

**Hint:** The command is simply the noun for the action.

### 8. What is Blade?

- Laravel's templating engine, compiled to plain PHP and cached.
- Laravel's CLI tool.
- Laravel's dependency injection container.
- A JavaScript framework bundled with Laravel.

**Hint:** It uses @-directives and .blade.php files.

### 9. How does Blade help prevent XSS by default?

- The {{ }} echo syntax escapes HTML entities automatically.
- It strips all HTML tags from output.
- It disables JavaScript in templates.
- It requires a CSP header on every page.

**Hint:** The double-brace echo does something protective to the value.

### 10. What is middleware in Laravel?

- A layer that filters or modifies HTTP requests entering the application, such as authentication.
- A database connection pool.
- A background job runner.
- A template partial.

**Hint:** It sits in the middle of the request and your controller.

### 11. How do you generate a controller with artisan?

- php artisan make:controller UserController
- php artisan new:controller UserController
- php artisan controller:create UserController
- php artisan generate UserController

**Hint:** artisan uses a make: prefix for scaffolding.

### 12. What does the service container provide?

- Dependency injection: it resolves and injects class dependencies automatically.
- A Docker container for the app.
- A cache store.
- A queue backend.

**Hint:** It is the heart of dependency injection in Laravel.

### 13. What is a service provider?

- A central place to register bindings and bootstrap parts of the application.
- A third-party API integration.
- A database seeder.
- A Blade component.

**Hint:** It is where you register things into the container.

### 14. Which Eloquent relationship models "a post has many comments"?

- hasMany
- belongsTo
- hasOne
- belongsToMany

**Hint:** One post, many comments.

### 15. Which relationship needs a pivot table?

- belongsToMany (many-to-many)
- hasOne
- hasMany
- belongsTo

**Hint:** Which one links two lists in both directions?

### 16. What protects Laravel forms against CSRF?

- A CSRF token included via @csrf, validated by middleware.
- Escaping output with {{ }}.
- The service container.
- Route caching.

**Hint:** A hidden token added by a Blade directive.

### 17. What are Eloquent migrations seeded with?

- Seeders and factories generate test/sample data.
- Middleware.
- Blade components.
- Service providers.

**Hint:** Think factories and db:seed.

### 18. What does Eloquent mass assignment protection prevent?

- Setting model attributes that are not listed as fillable from untrusted input.
- Running too many queries at once.
- Assigning the same value to many rows.
- Overloading the queue.

**Hint:** It is why models have a $fillable array.

### 19. How do you return JSON from a controller?

- return response()->json($data) (or just return an Eloquent model/collection)
- echo json_encode($data)
- return view($data)
- return $data->toBlade()

**Hint:** There is a helper on the response for this.

### 20. What is an API Resource in Laravel?

- A transformation layer that shapes a model into a JSON structure for API responses.
- A route group for APIs.
- A database table.
- A queue job.

**Hint:** It transforms a model into its JSON representation.

### 21. How does Laravel handle background work?

- Queued jobs processed by workers (php artisan queue:work).
- Blade directives.
- Route middleware.
- Service providers only.

**Hint:** Think queues and workers.

### 22. What does php artisan tinker give you?

- An interactive REPL to run code against your application.
- A production server.
- A migration generator.
- A front-end build tool.

**Hint:** It is an interactive shell for your app.

### 23. Where are environment-specific settings like DB credentials stored?

- In the .env file, read via config and the env() helper.
- In routes/web.php.
- In each controller.
- In the public directory.

**Hint:** A dotfile at the project root.

### 24. What is the purpose of php artisan config:cache in production?

- It combines all config into one cached file for faster boot.
- It clears the database cache.
- It compiles Blade templates.
- It runs migrations.

**Hint:** It is a boot-time performance optimization.

### 25. What does the belongsTo side of a relationship indicate?

- The model holds the foreign key pointing to its parent.
- The model owns many children.
- The relationship is many-to-many.
- The model has no relationships.

**Hint:** Which side stores the foreign key column?

### 26. How do you validate incoming request data in a controller?

- Call $request->validate([...]) or use a Form Request class.
- Wrap the logic in a try/catch only.
- Check each field manually with if statements exclusively.
- Validation is automatic and needs no code.

**Hint:** There is a validate() method on the request.
