What is an ORM and how does Eloquent work?
Why Interviewers Ask This
This question targets practical, hands-on experience with PHP. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.
Answer
An ORM (Object-Relational Mapper) maps database tables to PHP classes (models) and rows to objects, allowing you to interact with the database using PHP objects instead of writing raw SQL. Eloquent is Laravel's ORM. Define a model: class User extends Model { } — Eloquent automatically maps it to the users table. CRUD operations: User::find(1), User::create(["name" => "Alice"]), $user->update(["name" => "Bob"]), $user->delete(). Relationships are defined as methods: hasMany(), belongsTo(), belongsToMany(), hasOne(). Eloquent's fluent query builder: User::where("active", true)->orderBy("name")->paginate(20).
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong PHP candidates.