All interview guides

Laravel Interview Questions and Answers

24 questions that come up in Laravel technical interviews, each with the answer and an explanation of why it is right.

Test yourself — 90 question bank

1. What is Laravel?

Beginner

Answer: A PHP web application framework with expressive syntax

Laravel is a free, open-source PHP web application framework created by Taylor Otwell. It follows the MVC architectural pattern and emphasizes elegant syntax.

2. What are Laravel queues?

Advanced

Answer: Defer time-consuming tasks to background

Queues defer time-consuming tasks (emails, API calls) to background. Improves response time. Supports multiple drivers: database, redis, beanstalkd, SQS.

3. What is middleware in Laravel?

Intermediate

Answer: HTTP request filter

Middleware provides a mechanism for filtering HTTP requests. Can authenticate, log, modify requests/responses. Defined in app/Http/Middleware.

4. Which command creates a new Laravel project?

Beginner

Answer: Both a and b

Both `composer create-project laravel/laravel project-name` and `laravel new project-name` (requires Laravel Installer) create new Laravel projects.

5. How do you create a job?

Advanced

Answer: php artisan make:job JobName

`php artisan make:job JobName` creates a job. Dispatch with JobName::dispatch(). Run workers with `php artisan queue:work`.

6. How do you create middleware?

Intermediate

Answer: php artisan make:middleware MiddlewareName

`php artisan make:middleware MiddlewareName` creates middleware. Register in app/Http/Kernel.php in $middleware, $middlewareGroups, or $routeMiddleware.

7. What is Laravel authentication?

Intermediate

Answer: Both a and b

Laravel provides complete authentication system including registration, login, password reset. Use `php artisan make:auth` (Laravel UI) or Laravel Breeze/Jetstream.

8. What is Artisan?

Beginner

Answer: Laravel command-line interface for development tasks

Artisan is Laravel's command-line interface. It provides helpful commands for application development like migrations, seeding, and code generation.

9. What are Laravel events?

Advanced

Answer: Provide observer pattern implementation

Events provide observer pattern implementation. Decouple aspects of application. Event fired, listeners handle it. Register in EventServiceProvider.

10. What is event broadcasting?

Advanced

Answer: Broadcasts events to client-side via WebSockets

Broadcasting broadcasts server-side events to client-side JavaScript via WebSockets (Pusher, Ably, Laravel Echo). Enables real-time features.

11. What are Eloquent relationships?

Intermediate

Answer: Define relationships between models

Eloquent relationships define connections between models: hasOne, hasMany, belongsTo, belongsToMany, hasManyThrough, morphTo, morphMany.

12. What is a hasMany relationship?

Intermediate

Answer: One-to-many relationship

hasMany defines one-to-many relationship. Example: User hasMany Posts. Define in model: return $this->hasMany(Post::class).

13. What is a route in Laravel?

Beginner

Answer: Maps URLs to controllers or closures

Routes in Laravel map HTTP requests (URLs) to specific controller actions or closure functions. Defined in routes/ directory.

14. What is Laravel Echo?

Advanced

Answer: JavaScript library for WebSocket event listening

Laravel Echo is JavaScript library for subscribing to channels and listening to events broadcast by Laravel. Works with Pusher, Ably, Socket.io.

15. Where are routes defined in Laravel?

Beginner

Answer: routes/web.php and routes/api.php

Web routes are defined in routes/web.php, API routes in routes/api.php. Console routes in routes/console.php, channels in routes/channels.php.

16. What is API authentication with Sanctum?

Advanced

Answer: Lightweight authentication for SPAs and APIs

Sanctum provides lightweight authentication for SPAs and mobile apps. Issues API tokens, manages device tokens. Simpler alternative to Passport.

17. What is Laravel Passport?

Advanced

Answer: Full OAuth2 server implementation

Passport is full OAuth2 server implementation. Provides complete OAuth2 authorization. Use for complex API authentication requirements.

18. What is validation in Laravel?

Intermediate

Answer: Request data validation with rules

Validation validates incoming request data against rules. Use $request->validate() or Form Request classes. Laravel provides many built-in rules.

19. How do you validate a request?

Intermediate

Answer: $request->validate([rules])

$request->validate(['field' => 'required|email']) validates request. Automatically redirects back with errors on failure.

20. How do you create a controller?

Beginner

Answer: php artisan make:controller ControllerName

`php artisan make:controller ControllerName` creates a new controller. Add --resource flag for resourceful controller with CRUD methods.

21. What is testing in Laravel?

Advanced

Answer: Built-in testing with PHPUnit

Laravel provides testing with PHPUnit out of box. Write feature tests (HTTP tests) and unit tests. Run with `php artisan test`.

22. What is database testing with factories?

Advanced

Answer: Generate fake data for testing

Factories generate fake model data for testing and seeding. Use Faker library. Define in database/factories. Create with ModelName::factory()->create().

23. What is Blade in Laravel?

Beginner

Answer: Laravel templating engine

Blade is Laravel's powerful templating engine. Blade template files use .blade.php extension and allow PHP code with clean syntax.

24. What is a Form Request?

Intermediate

Answer: Custom request class with validation logic

Form Requests are custom request classes encapsulating validation logic. Created with `php artisan make:request RequestName`.

Ready to test yourself?

The full Laravel bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.

Take the Laravel quiz