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 What is the service container, and how does dependency injection work in Laravel?
The service container is Laravel's dependency-injection container: it knows how to build objects and their dependencies. When a controller, job or listener type-hints a class or interface, the…
-
Most asked What is the N+1 query problem in Eloquent and how do you prevent it?
N+1 happens when you load a list of models (1 query) and then access a relationship on each one, which lazy-loads it with one more query per model (N queries). Fix it with eager loading: with(),…
-
Most asked What is mass assignment, and how do $fillable and $guarded protect against it?
Mass assignment is creating or updating a model from an array, such as User::create($request->all()). Without protection, a client can set columns it should never control, like is_admin or balance.
-
Most asked What are the most common security mistakes in Laravel applications?
Mass assignment from raw input, missing authorization on endpoints, SQL injection through raw queries with interpolated values, XSS through {!! !!}, exposed debug mode or .env, and secrets committed…
-
Most asked What are API Resources and why use them?
API Resources (JsonResource) transform models into JSON in one place, controlling exactly which fields are exposed, formatting values, including relationships only when loaded, and wrapping…
-
Most asked What is Laravel Octane, and what changes when you use it?
Octane serves the app with a long-running server (FrankenPHP, Swoole or RoadRunner) that boots the framework once and keeps it in memory between requests, which removes bootstrap cost and greatly…
-
What is route-model binding? Explain implicit, explicit and scoped binding.
Route-model binding turns a route parameter into a model instance automatically. If the model is not found, Laravel returns a 404.
-
What are local and global query scopes?
Local scopes are reusable query constraints you call explicitly (Order::paid()->recent()); global scopes are applied automatically to every query on the model, such as soft deletes or multi-tenancy…
-
What is Laravel Horizon and when do you need it?
Horizon is a dashboard and supervisor for Redis queues: it configures worker processes in code, auto-balances workers across queues, and shows throughput, wait times, failed jobs and job metrics.
-
What are Laravel's job batching and job chaining, and when would you use each?
Chaining (Bus::chain([...])) runs jobs one after another, stopping if one fails. Batching (Bus::batch([...])) runs many jobs in parallel and tracks overall progress, with then, catch and finally…
-
What are Laravel contracts?
Contracts are the interfaces (in Illuminate\Contracts) that define the framework's core services, such as Cache\Repository, Queue\Queue and Mail\Mailer.
-
What are model factories and seeders used for?
Factories generate model instances with fake data for tests and local development; seeders populate the database with data, using factories or fixed records.
-
What are Laravel collections and lazy collections?
Collection wraps arrays with chainable methods (map, filter, groupBy, keyBy, sum, chunk); LazyCollection uses PHP generators so items are produced one at a time, which keeps memory flat for large…
-
What are signed URLs and when would you use them?
Signed URLs (URL::signedRoute, URL::temporarySignedRoute) carry an HMAC signature of the URL, so the app can verify the link was generated by it and has not been changed. Typical uses: unsubscribe…