Updated June 2026. Tested on Laravel 13 and PHP 8.4.

Eloquent is Laravel's ORM, which stands for object relational mapper. It follows the active record pattern, where each database table has a matching model class, and you work with rows as objects instead of writing raw SQL. You read, create, update and delete records by calling methods on the model. Under the hood Eloquent builds the SQL for you.

The thing that makes Eloquent pleasant is convention. If you name things the way it expects, you write almost no configuration. Let me walk through those conventions, because once you know them the rest of Eloquent makes sense.

Define a model

Models live in app/Models and extend Illuminate\Database\Eloquent\Model. The quickest way to make one is the artisan generator.

php artisan make:model Product

That gives you a small class.

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    //
}

Table name

Notice we never told Eloquent which table to use. By convention it takes the snake case plural of the class name, so Product maps to the products table. If your table is named differently, set it explicitly.

protected $table = 'my_products';

Primary key

Eloquent assumes each table has an auto incrementing integer primary key called id. You can change the column name, and if your key is not an auto incrementing integer you tell it so.

protected $primaryKey = 'product_id';
public $incrementing = false;   // if the key is not auto incrementing
protected $keyType = 'string';  // if the key is not an integer, e.g. a UUID

Timestamps

By default Eloquent expects created_at and updated_at columns and keeps them up to date for you. If your table does not have them, turn the feature off.

public $timestamps = false;

You can also rename the columns or change the stored format if you ever need to.

const CREATED_AT = 'creation_date';
const UPDATED_AT = 'last_update';

Casting attributes

This is the convention you will use most. Casts turn raw database values into proper PHP types when you read them, and back again when you save. In modern Laravel you define them in a casts method.

protected function casts(): array
{
    return [
        'is_active'   => 'boolean',
        'price'       => 'decimal:2',
        'options'     => 'array',
        'released_at' => 'datetime',
    ];
}

Now $product->is_active is a real boolean and $product->options is a real array, not a string from the database.

Database connection

Every model uses the default connection from config/database.php. If a model should use a different one, name it. This is the hook that makes multi database and multi tenant setups possible.

protected $connection = 'tenant';

That is the foundation. A model is a thin class that, thanks to these conventions, already knows its table, key, timestamps and types. From here you can start querying, which the next articles cover. If you have a question about Eloquent models, leave a comment below.