← All notes

Laravel Eloquent models map a class to a table by convention; use fillable for mass assignment

Answer: Generate a model with php artisan make:model Flight -m, then query it like a query builder, for example Flight::where('active', 1)->orderBy('name')->get(). By convention the Flight model uses the flights table, an id primary key, and created_at and updated_at timestamps.

Example

<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Flight extends Model
{
    use SoftDeletes;
    protected $table = 'my_flights';
    protected $primaryKey = 'flight_id';
    protected $fillable = ['name'];
}
$flights = Flight::where('active', 1)->orderBy('name')->limit(10)->get();
$flight = Flight::create(['name' => 'London to Paris']);
$flight = Flight::firstOrCreate(['name' => 'London to Paris']);
Flight::find(1)->delete();

Conventions

Creating and finding

Deleting

Call delete on a model instance. With the SoftDeletes trait, the deleted_at attribute is cast to a DateTime / Carbon instance, and you should add a deleted_at column to the table.

Generating

make:model with --migration or -m also creates a database migration; other options generate factories, seeders, policies, controllers and form requests.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Laravel docs, Eloquent: Getting Started; laravel/docs (GitHub), eloquent.md (source page). MIT (https://raw.githubusercontent.com/laravel/docs/12.x/license.md). Copyright Taylor Otwell. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Laravel docs, Eloquent: Getting Started; laravel/docs (GitHub), eloquent.md (source page). MIT (https://raw.githubusercontent.com/laravel/docs/12.x/license.md). Copyright Taylor Otwell.

Cite this

Permanent ID: iil:note:pkbc07dm

iinventedlight. 2026. "Laravel Eloquent models map a class to a table by convention; use fillable for mass assignment." iinventedlight Library, iil:note:pkbc07dm, version of 2026-11-18. https://iinventedlight.com/library/notes/laravel-eloquent-models/. License: CC-BY-4.0.

@misc{iil_note_pkbc07dm,
  author = {{iinventedlight}},
  title = {{Laravel Eloquent models map a class to a table by convention; use fillable for mass assignment}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/laravel-eloquent-models/},
  note = {Permanent ID iil:note:pkbc07dm. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/laravel-eloquent-models.md.