Advertisement
Beginner PHP, Eloquent ORM & Doctrine ORM

What is an Object Relational Mapper, and how do Eloquent and Doctrine represent two different popular approaches within the PHP ecosystem?

Short answer

An Object Relational Mapper, or ORM, lets you interact with a database using ordinary PHP objects and method calls rather than writing raw SQL queries directly, with Eloquent, Laravel's built in ORM, following the Active Record pattern where a model class directly represents…

Save PHP mock interview
Advertisement
AModel answer
An Object Relational Mapper, or ORM, lets you interact with a database using ordinary PHP objects and method calls rather than writing raw SQL queries directly, with Eloquent, Laravel's built in ORM, following the Active Record pattern where a model class directly represents both the data and the ability to save or query that data, while Doctrine, commonly used with Symfony, follows the Data Mapper pattern, keeping entity classes completely separate from the actual database persistence logic, which is handled by a separate entity manager.
// Eloquent Active Record style
$user = User::find(1);
$user->name = 'Ali';
$user->save();
Real-world example
A Laravel application uses Eloquent to fetch a user record and directly call a save method on that same object to persist changes, reflecting the Active Record pattern's philosophy of combining data and persistence behavior together.
Likely follow-ups
  • What is the practical difference between the Active Record and Data Mapper patterns?
  • Can Doctrine be used within a Laravel application instead of Eloquent?
Related topics