Eloquent

Noun · Development

Definitions

  1. The object-relational mapper built into the Laravel PHP framework, implementing the Active Record pattern, where each model class corresponds to a database table and each model instance to a row. A model such as User can be queried fluently, as in User::where('active', true)->orderBy('name')->get(), with Eloquent generating the SQL through Laravel's query builder. Relationships are declared as methods using hasOne, hasMany, belongsTo, belongsToMany, and polymorphic variants, then accessed as properties. Because related records load lazily by default, looping over models and touching a relationship can trigger the N+1 query problem, which eager loading with with() solves. Other features include query scopes for reusable conditions, accessors and mutators for transforming attributes, attribute casting, soft deletes, model events, and mass-assignment protection through the $fillable and $guarded properties. Eloquent's expressiveness is a large part of Laravel's appeal, though it shares Active Record's tendency to couple business logic to the database schema.

    In plain English: Laravel's built-in tool for working with databases in PHP — each database table becomes a class, and you interact with data using simple method calls.

    Example: "With Eloquent, fetching a user's posts is just $user->posts — it lazy-loads the relationship automatically."

Related Terms