Laravel interview questions

Request lifecycle, service container, Eloquent and N+1, queues, validation, auth and the questions that separate Laravel users from Laravel developers.

Readiness: 0 of 28 nailed

How to use this page: 1. Read a question2. Type your answer3. Check with AI4. Open the model answer5. Timed drill when you’re 70% ready

Core concepts

JuniorConcept

Walk me through the Laravel request lifecycle.

Mid-levelConcept

What is the service container and dependency injection in Laravel?

Mid-levelConcept

When would you use events and listeners instead of putting code in the controller?

JuniorConcept

What are facades, and how do they work under the hood?

Mid-levelConcept

How does the container resolve a class with dependencies it was never told about?

Eloquent

JuniorIt’s broken: why?

This page runs 101 queries. Why, and how do you fix it?

$posts = Post::latest()->take(100)->get();
foreach ($posts as $post) {
  echo $post->author->name;
}
JuniorConcept

What is mass assignment and what are $fillable and $guarded?

JuniorConcept

Explain hasMany, belongsTo, belongsToMany and polymorphic relations.

JuniorWrite it by hand

What are query scopes? Write one.

JuniorConcept

What are casts and accessors/mutators?

Mid-levelWrite it by hand

You need to update 2 million rows with Eloquent. How do you avoid running out of memory?

Requests

JuniorWrite it by hand

Validate a registration request properly.

FoundationWrite it by hand

Write middleware that only allows admins.

Queues and jobs

Mid-levelReal-world scenario

Sending a welcome email makes registration take 4 seconds. How do you fix it?

Mid-levelIt’s broken: why?

Queued jobs are stuck or silently failing. What do you check?

Auth

Mid-levelConcept

Sanctum vs Passport: which would you use for an SPA and a mobile app?

JuniorConcept

What are Gates and Policies?

Mid-levelIt’s broken: why?

Your SPA gets 419 CSRF token mismatch or 401 with Sanctum. What’s wrong?

Database

FoundationConcept

What are migrations and why shouldn’t you edit an old migration?

JuniorWrite it by hand

How do you use database transactions in Laravel?

Deployment

Mid-levelIt’s broken: why?

After deploy, env('API_KEY') returns null in production. Why?

Performance

Mid-levelReal-world scenario

A Laravel endpoint is slow in production. How do you debug it?

JuniorWrite it by hand

Cache an expensive query in Laravel and invalidate it properly.

SeniorConcept

What is Laravel Octane, and what new bugs can it introduce?

APIs

JuniorConcept

What are API Resources?

Testing

JuniorConcept

How do you test a Laravel application?

Architecture

SeniorReal-world scenario

How would you structure a large Laravel application?

SeniorReal-world scenario

Design a URL shortener in Laravel.

Also prepare