Skip to main content

Database for Laravels

Laravel database work centres on migrations, seeders and the Eloquent ORM. Migrations version the schema in PHP files, seeders and factories insert sample data, and Eloquent maps each table to a model class with relationships such as hasMany and belongsTo, so queries read as method calls.

Stage: Data Layer · Part of the Laravel roadmap · Last reviewed 19 November 2026

What to learn in Database

Database interview questions

What is the N+1 query problem in Eloquent?

It happens when you loop over a collection and access a relationship for each item, causing one query for the list plus one per item. Fix it with eager loading, using with() so related records are fetched in a small, fixed number of queries.

What does mass assignment protection do?

When you call create or fill with request data, an attacker could set columns you never intended, such as is_admin. The fillable property lists the allowed columns, and guarded lists the blocked ones, so only approved fields can be set this way.

Where Database fits in the Laravel roadmap

Database belongs to the Data Layer stage (intermediate level), which takes about 20 hours. Eloquent.

Back to the full Laravel roadmap