Interview Q&A · questions with model answers
Laravel Interview Questions
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked How do you validate requests in Laravel? Why use Form Requests?
Use $request->validate([...]) for simple cases, or a Form Request class that holds the rules, authorization check and custom messages. On failure Laravel redirects back with errors (web) or returns…
-
Most asked How do you process a very large table in Laravel without running out of memory?
Do not use get() or all(). Use chunkById() (batches by primary key), lazyById() (a lazy collection over chunks) or cursor() (one model at a time from a single query), and select only the columns you…
-
Most asked How do you use caching in Laravel effectively, including atomic locks?
Cache::remember($key, $ttl, fn () => ...) implements cache-aside; choose Redis or Memcached in production; invalidate on writes; and use Cache::lock() atomic locks to protect critical sections or…
-
Most asked How do you test a Laravel application? Feature tests, unit tests and fakes.
Feature tests send HTTP requests through the whole framework ($this->postJson('/api/orders', ...)->assertCreated()); unit tests cover isolated classes. Laravel's fakes (Queue::fake(), Mail::fake(),…
-
Most asked How do you deploy a Laravel application with zero downtime?
Build each release in a new directory (dependencies installed, assets built, config cached), run backward-compatible migrations, switch a symlink atomically, reload PHP-FPM/OPcache, and restart…
-
Most asked How do you protect an endpoint against race conditions in Laravel, for example two users buying the last item?
Make the check and the write atomic: a conditional update (update ... where stock > 0), a row lock inside a transaction (lockForUpdate()), or a distributed lock (Cache::lock) for logic spanning…
-
How do you write migrations that are safe to deploy with zero downtime?
Make every migration backward compatible with the code still running: add before you use, and remove only after nothing uses it (expand and contract). Avoid long table locks on large tables.
-
How do you make queued jobs idempotent and prevent duplicates in Laravel?
Design the job so running it twice has the same effect as running it once: check and record what was done in the database (ideally with a unique constraint), and use Laravel's helpers…
-
How do you call external APIs reliably with Laravel's HTTP client?
Use the Http facade with an explicit timeout() and connectTimeout(), retry() with backoff for transient failures, throw() (or check failed()) for HTTP errors, and Http::fake() in tests.
-
How do you implement rate limiting in Laravel?
Define named limiters with RateLimiter::for() (usually in a service provider) and apply them with the throttle:name middleware; limits can depend on the user, plan or IP, and the limiter returns 429…
-
How do you define indexes and foreign keys in Laravel migrations?
Use $table->foreignId('user_id')->constrained()->cascadeOnDelete() for foreign keys, ->index() / ->unique() on columns, and $table->index(['tenant_id', 'created_at']) for composite indexes matching…
-
How do you configure logging in Laravel for production?
Logging uses Monolog channels configured in config/logging.php: stack combines channels, daily rotates files, and drivers such as stderr, syslog, slack and papertrail send logs elsewhere. In…
-
How do you upgrade a Laravel application across major versions?
Upgrade one major version at a time, follow the official upgrade guide, update first-party and third-party packages, run the test suite, and fix deprecations before they become removals. Automated…