Skip to main content

Laravel Interview Questions

Static Q&A bank with reviewed/starred tracking (20 questions). For timed rule-based sessions, use the Guided Interview Assessment lab.

Open Guided Interview Assessment →

Interview prep workspace

Local-first progress · Pro unlocks cross-device sync

Question bank stays free.

Select up to 40 questions for a one-time workbook. These questions have a topic. They do not have a role field, so the PDF is grouped by topic and by company only when the question names one.

0 selected.

One-time add-on

Company Interview Preparation Pack

Download the questions you selected, with space to plan answers.

  • Free: the full question bank on this page, including the existing free PDF
  • You receive: a workbook of your selected questions, a checklist, and notes pages
  • Access: Downloadable workbook, one-time. This purchase does not start Priygop Pro.
Price loading
Quick Answer

Laravel is a PHP web framework that provides structure, conventions, and batteries-included tools (routing, ORM, auth, queues) so you build apps faster and more securely than raw PHP.

Detailed Explanation

Laravel follows MVC, uses Composer packages, and ships with Eloquent, Blade, Artisan, middleware, validation, and testing support. It reduces boilerplate around HTTP, SQL, and security (CSRF, hashing, mass assignment). Modern Laravel targets PHP 8.2+.

Quick Answer

Route matches URL → Controller handles input/auth → Model (Eloquent) reads/writes data → Blade View returns HTML.

Detailed Explanation

Example: GET /posts/1 → PostController@show(Post $post) → Eloquent loads the post → return view('posts.show', compact('post')). Keeping controllers thin and pushing rules into Form Requests/Policies is a common interview expectation.

Quick Answer

Artisan is Laravel's CLI. Common: make:model -mfs, make:controller --resource, migrate, tinker, route:list, test, queue:work.

Detailed Explanation

Artisan scaffolds classes consistently and runs framework tasks. Interviewers often ask how you'd generate a resource controller or roll back a migration (migrate:rollback).

Quick Answer

So only index.php and public assets are web-accessible; app code, .env, and vendor stay outside the web root.

Detailed Explanation

Pointing Nginx/Apache at the project root can leak .env secrets and source files. public/index.php is the front controller.

Quick Answer

{{ }} escapes HTML (XSS-safe). {!! !!} renders raw HTML and must only be used for trusted/sanitized content.

Detailed Explanation

Blade compiles to PHP htmlspecialchars for {{ }}. Using raw output for user content is a classic security footgun.

Quick Answer

Laravel resolves a route parameter into an Eloquent model automatically, or returns 404 if missing.

Detailed Explanation

show(Post $post) looks up Post by id (or custom route key like slug). Explicit binding and scoped bindings exist for nested resources.

Quick Answer

Use $fillable or $guarded on models and pass only validated input ($request->validated()).

Detailed Explanation

Never create($request->all()) on user models. Attackers can inject is_admin=1 if fields are unguarded.

Quick Answer

Lazy-loading relations inside a loop causes 1 + N queries. Fix with eager loading: with('relation').

Detailed Explanation

Post::with('user','tags')->paginate() loads relations in bulk. Tools: Laravel Debugbar, Telescope, or DB::listen to spot N+1.

Quick Answer

When validation/authorization for a form or endpoint should leave the controller — rules(), messages(), authorize().

Detailed Explanation

Type-hint StorePostRequest in the controller; after injection, validation already passed and validated() is available.

Quick Answer

Gates for simple ability checks; Policies for model-centric authorization (update/delete this Post).

Detailed Explanation

Policies scale with resources and integrate with $this->authorize() and @can in Blade. Gates fit cross-cutting abilities like 'access-admin'.

Quick Answer

Session CSRF token is embedded with @csrf; VerifyCsrfToken middleware rejects mismatched tokens on state-changing requests (419).

Detailed Explanation

APIs using tokens (Sanctum) often exclude routes differently; SPAs may use cookie-based CSRF. Never disable CSRF casually on web forms.

Quick Answer

SoftDeletes sets deleted_at instead of removing the row; default queries hide trashed models.

Detailed Explanation

withTrashed()/onlyTrashed(), restore(), forceDelete(). Useful for recycle-bin UX and auditability.

Quick Answer

Prefix routes (/api/v1), use API Resources for stable payloads, Sanctum/Passport for auth, throttle, and document breaking changes in v2.

Detailed Explanation

Keep controllers thin, transform with JsonResource, paginate collections, return consistent error JSON, and cover with feature tests.

Quick Answer

Slow or failure-prone side effects: mail, image processing, webhooks, reports — anything that shouldn't block the HTTP response.

Detailed Explanation

Implement ShouldQueue, configure drivers (database/redis), run queue:work/Horizon, handle failed_jobs and retries, and make jobs idempotent when possible.

Quick Answer

composer install --no-dev -o; php artisan migrate --force; config:cache; route:cache; view:cache; restart queue workers.

Detailed Explanation

APP_DEBUG=false, strong APP_KEY, HTTPS. Avoid config:cache with missing env during build. Clear caches when config changes.

Quick Answer

It resolves class dependencies via constructor injection and bindings registered in service providers.

Detailed Explanation

Controllers, jobs, and listeners can type-hint interfaces; providers bind implementations. This enables testing with fakes/mocks and cleaner architecture.

Quick Answer

Measure queries (Telescope/Debugbar), check for N+1, missing indexes, oversized pages, and uncached expensive aggregates.

Detailed Explanation

Eager load relations, add indexes on foreign keys/filters, paginate, cache hot read models carefully with invalidation, and profile SQL EXPLAIN.

Quick Answer

auth middleware + PostPolicy::update comparing user id to post.user_id + authorize() in controller and @can in Blade.

Detailed Explanation

Defense in depth: hide UI, enforce in Form Request authorize(), and still authorize in controller. Return 403 for forbidden.

Quick Answer

Inspect failed_jobs, add retries/backoff, make the job idempotent, fix SMTP/config, alert on failures, and re-queue after fix.

Detailed Explanation

Check worker supervision (Supervisor), timeout settings, and whether the job assumed request/session state that queues don't have.

Quick Answer

Sanctum is simpler for first-party SPAs and personal API tokens; Passport is full OAuth2 for third-party client ecosystems.

Detailed Explanation

Sanctum covers cookie SPA auth and token APIs with less ceremony. Passport fits multi-client OAuth (authorization code, clients, scopes) at higher complexity.

Ready to master Laravel Interview Questions?

Start learning with our comprehensive course and practice these questions.