← certdrill.dev home

Laravel Quiz

21 questions / 10 random questions

routing controllers Eloquent migrations validation middleware queues Blade and auth
Try a 10-question Laravel quiz

Random questions, instant feedback, and review for missed questions.

Start quiz →

Included topics (21 questions)

Q1

In Laravel, you want GET /users/{user} to call UserController@show. Which route definition is most natural?

Answer: Route::get('/users/{user}', [UserController::class, 'show']);

Route::get defines a route for GET requests. The array form can specify the controller class and method.

Q2

In Laravel, you want to receive a User model automatically from the {user} route parameter. Which feature is mainly used?

Answer: Route model binding

Route model binding can inject the matching Eloquent model into a controller argument from a route parameter.

Q3

In a Laravel controller, what is preferable to reading request input directly from $_POST?

Answer: Receive a Request object, validate it, and use it

Laravel's Request object lets you handle input, authorization, and validation using framework conventions.

Q4

Input validation is complex and reused by multiple controllers. Where is it natural to move it in Laravel?

Answer: Form Request class

A Form Request can move authorization and validation rules into a dedicated class, helping keep controllers thin.

Q5

In Laravel, for a one-to-many relationship between users and posts, which relation is typically defined on the User model?

Answer: hasMany(Post::class)

Because a user has many posts, the User model defines hasMany. From the post side back to the user, belongsTo is used.

Q6

A list page displays posts and authors and suffers from N+1 queries. What should you consider first in Laravel?

Answer: Use eager loading with with('user')

Eager loading preloads related models and reduces additional queries inside loops.

Q7

In Laravel, which model property is commonly used to handle mass assignment safely?

Answer: $fillable

$fillable explicitly lists attributes allowed for mass assignment. It helps prevent unintended column updates.

Q8

In Laravel, what is used to share database schema changes across a team and manage them as history?

Answer: Migration

Migrations manage database schema changes such as creating tables or adding columns as code.

Q9

Why does migration order matter when dropping tables with foreign key constraints?

Answer: Dropping a referenced table first can violate constraints

With foreign key constraints, you must plan the order, such as dropping constraints or child tables first.

Q10

In Laravel, you want to validate that email is required and has email format. Which rule set is representative?

Answer: 'email' => ['required', 'email']

required checks presence, and email checks email format. Complex inputs are often managed in a Form Request.

Q11

When validation fails in Laravel, what is the usual behavior for a normal web request?

Answer: Redirect back and flash error information to the session

For web requests, validation failure commonly redirects back and makes errors and old input available for display.

Q12

In Laravel, you want to restrict a route to authenticated users. What is commonly used?

Answer: auth middleware

The auth middleware protects routes that require authentication, such as redirecting guests to a login page.

Q13

In Laravel, where is CSRF protection mainly needed?

Answer: State-changing form submissions and POST/PUT/DELETE requests

CSRF abuses a user's authenticated state to cause unintended state changes. Token verification matters for state-changing requests.

Q14

You want to defer heavy work such as sending mail or processing images so the HTTP response is not delayed. What Laravel feature is commonly used?

Answer: Queue Job

Queue Jobs let you dispatch heavy work to a queue and process it asynchronously with workers.

Q15

Why is it often necessary to restart Laravel queue workers after deployment?

Answer: Workers are long-running and may not automatically reload new code

Queue workers are long-running processes, so deployment often requires restarting them to load new code or configuration.

Q16

Why is Blade's normal {{ $name }} output considered safer for displaying user input in HTML?

Answer: Because it outputs HTML-escaped content

Blade's {{ }} output is escaped by default. Raw output with {!! !!} should be used carefully.

Q17

You want to reuse a shared header or form part across multiple screens. What is a good Blade candidate?

Answer: Blade component

Blade components can reuse view parts and reduce template duplication.

Q18

In Laravel, where is it appropriate to organize logic that decides whether the logged-in user can update a specific post?

Answer: Policy

Policies organize authorization logic for models and reduce scattered checks in controllers or Blade views.

Q19

You want to get the authenticated user's information in a Laravel controller. Which method is representative?

Answer: $request->user()

$request->user() is a common way to get the currently authenticated user. Authorization can be combined with policies or gates.

Q20

In Laravel production, .env was changed but configuration did not update. What should you suspect first?

Answer: config cache

Production often uses config:cache. If configuration is cached, the cache must be regenerated after .env changes.

Q21

In Laravel, you want secrets to vary by environment without hard-coding them. What is the basic approach?

Answer: Use .env or external secret management and read through config

Secrets should be separated from source code and supplied through environment variables or secret management into configuration.

certdrill.dev is an independent, unofficial learning site and is not affiliated with LPI Japan, IPA, AWS, Microsoft Azure, or any exam provider. Questions and explanations are original content.