Basic Laravel Interview Questions
Core Concepts
1. What is Laravel and why use it? Laravel is a PHP framework following the MVC pattern. It provides routing, ORM, authentication, caching, and queues out of the box, reducing boilerplate and speeding up development.
2. What is the MVC pattern in Laravel? Model handles data/database logic, View handles presentation (Blade templates), Controller handles request logic and connects Model to View.
3. What is Artisan? Laravel's command-line tool. Used to run migrations, create files, clear cache, manage queues, etc. (php artisan make:controller, php artisan migrate).
Routing
4. How do you define a basic route?
php
Route::get('/users', [UserController::class, 'index']);
Route::post('/users', [UserController::class, 'store']);
5. What are route parameters?
php
Route::get('/users/{id}', [UserController::class, 'show']);
{id} is required; {id?} is optional.
6. What is a named route?
php
Route::get('/users', [UserController::class, 'index'])->name('users.index');
// Use it: route('users.index')
Controllers & Middleware
7. What is a Resource Controller? php artisan make:controller UserController --resource generates 7 standard methods: index, create, store, show, edit, update, destroy.
8. What is Middleware? Code that runs before/after a request hits your controller. Used for authentication, logging, CORS, etc. Attach with ->middleware('auth') on routes.
Eloquent ORM
9. What is Eloquent? Laravel's ORM. Each database table maps to a Model class, letting you interact with data using PHP instead of raw SQL.
php
User::all();
User::find(1);
User::where('active', 1)->get();
10. What are the basic Eloquent relationships?
hasOne — one-to-one
hasMany — one-to-many
belongsTo — inverse of hasOne/hasMany
belongsToMany — many-to-many
hasOneThrough / hasManyThrough — indirect relationships
11. What is a migration? A version-controlled file that defines DB schema changes. Run with php artisan migrate, rollback with php artisan migrate:rollback.
12. What is a Factory and Seeder? Factories generate fake model data for testing. Seeders populate the database with initial/test data. Run with php artisan db:seed.
Blade Templates
13. What is Blade? Laravel's templating engine. Compiles to plain PHP and is cached for performance.
blade
{{ $name }} {{-- echo, escaped --}}
{!! $html !!} {{-- echo, unescaped --}}
@if / @foreach / @extends / @section / @yield
14. What is template inheritance in Blade? A layout file uses @yield('content'). Child views use @extends('layout') and @section('content') to fill slots.
Validation & Requests
15. How do you validate a request?
php
$request->validate([
'email' => 'required|email',
'name' => 'required|min:3',
]);
Or use a Form Request class (php artisan make:request).
Miscellaneous
16. What is the .env file? Stores environment-specific config like DB credentials, API keys, app URL. Never commit it to version control.
17. What is the difference between dd() and dump()? dd() dumps and dies (stops execution). dump() outputs the value and continues execution.
18. What is php artisan tinker? An interactive REPL shell to run Laravel/PHP code directly against your app — useful for testing queries and logic quickly.
Laravel
PHP
MySQL
Conversation
Reader notes
Log in to add your voice to this discussion.
Log inSachin
4 hours ago
✈️🙌
Admin User
4 hours ago
Wow 😯
Reader User
3 days ago
nice 👍👍
Author User
3 days ago
share