← Back to Course

Defining Models and Migrations

Every Eloquent model needs a matching database table to represent, and Laravel uses migrations to define that structure in code. Together, models and migrations form the backbone of how a Laravel application manages its data layer.

What Is a Model?

A model is a PHP class, usually generated through Artisan, that represents a single database table. By convention, Laravel assumes a model named Post corresponds to a table named posts, though this can be overridden when needed.

What Is a Migration?

A migration is a version-controlled PHP file that describes changes to the database schema, such as creating a table or adding a column. Because migrations live alongside application code, the entire team can stay in sync on the database structure without manually running SQL scripts.

File TypePurpose
ModelRepresents and interacts with a database table in PHP
MigrationDefines or modifies the actual table structure
FactoryGenerates fake data for testing based on a model
SeederPopulates the database with initial or sample records

Generating Both Together

With a model and its matching table structure in place, the model is finally ready to actually store and retrieve data — starting with the basic CRUD operations covered next.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course