Laravel Interview Questions and Answers (Beginner to Advanced)
A complete collection of Laravel interview questions with clear answers, covering core concepts, backend development, APIs, and real-world scenarios.
Laravel Interview Questions and Answers
1. What is Laravel?
Laravel is a PHP web application framework that follows the MVC (Model-View-Controller) architecture. It provides elegant syntax and built-in tools for routing, authentication, ORM, caching, queues, and testing.
2. What are the features of Laravel?
Key features include:
- Eloquent ORM
- Blade templating engine
- Routing system
- Middleware
- Authentication & Authorization
- Artisan CLI
- Queue management
- Task scheduling
- Database migrations
- API support
3. Explain MVC architecture in Laravel.
- Model → Handles database logic
- View → UI layer
- Controller → Handles requests and business logic
Flow: User Request → Route → Controller → Model → View → Response
4. What is Artisan in Laravel?
Artisan is Laravel’s command-line interface.
Example commands:
php artisan serve
php artisan migrate
php artisan make:model User
php artisan make:controller UserController
5. What is Eloquent ORM?
Eloquent is Laravel’s Object Relational Mapper (ORM) used to interact with databases using models instead of raw SQL.
Example:
$users = User::all();
6. What are migrations?
Migrations are version control for databases.
Example:
php artisan make:migration create_users_table
Example migration:
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
7. What is middleware?
Middleware filters HTTP requests before they reach controllers.
Example:
Route::middleware(['auth'])->group(function () {
Route::get('/dashboard', function () {
return view('dashboard');
});
});
8. Difference between GET and POST routes?
- GET → Fetch data
- POST → Submit data
Example:
Route::get('/users', [UserController::class, 'index']);
Route::post('/users', [UserController::class, 'store']);
9. What is CSRF protection?
Laravel protects forms against Cross-Site Request Forgery attacks using CSRF tokens.
Example:
<form method="POST">
@csrf
</form>
10. What is Blade templating?
Blade is Laravel’s templating engine.
Example:
@if($user)
Welcome {{ $user->name }}
@endif
11. What is dependency injection in Laravel?
Laravel automatically injects class dependencies into constructors or methods.
Example:
public function __construct(UserService $service)
{
$this->service = $service;
}
12. Explain Service Container.
The service container manages class dependencies and performs dependency injection.
Example:
app()->make(UserService::class);
13. What are Laravel facades?
Facades provide static-like access to Laravel services.
Example:
Cache::put('key', 'value', 60);
14. What is routing in Laravel?
Routing maps URLs to controllers or closures.
Example:
Route::get('/home', function () {
return view('home');
});
15. What is RESTful resource controller?
Resource controllers provide standard CRUD routes.
Example:
Route::resource('users', UserController::class);
16. What are Laravel events and listeners?
Events allow decoupled communication between components.
Example:
event(new UserRegistered($user));
17. What is queue in Laravel?
Queues process time-consuming tasks asynchronously.
Example use cases:
- Sending emails
- Notifications
- File uploads
18. What is Laravel Scheduler?
Scheduler automates recurring tasks.
Example:
$schedule->command('emails:send')->daily();
19. Explain authentication in Laravel.
Laravel provides built-in authentication using:
- Laravel Breeze
- Jetstream
- Sanctum
- Passport
20. Difference between hasOne and belongsTo?
hasOne→ Parent owns childbelongsTo→ Child references parent
Example:
public function profile()
{
return $this->hasOne(Profile::class);
}
Advanced Laravel Interview Questions
21. What is Repository Pattern in Laravel?
It separates business logic from data access logic.
22. What are Laravel Policies and Gates?
Used for authorization.
- Gate → Simple authorization
- Policy → Model-based authorization
23. What is eager loading?
Used to reduce N+1 query problems.
Example:
User::with('posts')->get();
24. What is the N+1 query problem?
When multiple queries are executed unnecessarily while fetching related models.
25. What is Laravel Sanctum?
Used for lightweight API authentication.
26. What is Laravel Passport?
OAuth2 authentication package for APIs.
27. What is caching in Laravel?
Caching improves performance.
Supported drivers:
- Redis
- Memcached
- File
- Database
Example:
Cache::remember('users', 60, function () {
return User::all();
});
28. What are observers in Laravel?
Observers listen to model events.
Example:
UserObserver@created
29. Explain Laravel lifecycle.
- Request enters
public/index.php - Service container boots
- Middleware executes
- Route matched
- Controller executes
- Response returned
30. How do you optimize a Laravel application?
Commands:
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan optimize
Scenario-Based Laravel Questions
31. How would you handle file uploads?
Use:
$request->file('image')->store('images');
32. How would you create an API in Laravel?
Steps:
- Create routes in
api.php - Create controller
- Use API resources
- Authenticate using Sanctum/Passport
33. How do you handle validation?
Example:
$request->validate([
'name' => 'required',
'email' => 'required|email'
]);
34. What is soft delete?
Records are marked deleted without removing them.
Example:
use SoftDeletes;
35. How do you create custom middleware?
php artisan make:middleware CheckAge
Experienced-Level Questions
36. Difference between env() and config()
env()→ Reads environment variablesconfig()→ Reads cached configuration values
37. Explain IoC Container.
Inversion of Control container resolves dependencies automatically.
38. What are contracts in Laravel?
Interfaces provided by Laravel services.
Example:
Illuminate\Contracts\Queue\Queue
39. What is API Resource in Laravel?
Transforms models into JSON responses.
Example:
return new UserResource($user);
40. Explain Laravel package development.
Packages extend Laravel functionality using:
- Service providers
- Facades
- Composer
HR + Practical Questions
41. Which Laravel version have you worked on?
Mention:
- Laravel 8/9/10/11
- Features you used
42. Describe a challenging Laravel project you worked on.
Focus on:
- Architecture
- Performance optimization
- API integrations
- Scalability
43. How do you improve Laravel performance?
- Caching
- Queues
- Database indexing
- Eager loading
- Redis
44. How do you secure Laravel applications?
- CSRF protection
- Validation
- Rate limiting
- HTTPS
- SQL injection prevention
- Authentication
45. Explain your deployment process.
Mention:
- Git
- CI/CD
- Docker
- Nginx/Apache
- Supervisor
- Queue workers
Common Coding Questions
Reverse a string
$str = "Laravel";
echo strrev($str);
Find duplicate records using Eloquent
User::select('email')
->groupBy('email')
->havingRaw('COUNT(*) > 1')
->get();
Fetch users with posts
User::with('posts')->get();