← Laravel learning pathLaravel · Module 5 of 10
Eloquent ORM
Work with database records as PHP objects.
📖 Key ideas
- Create a model: php artisan make:model Post -m (with migration).
- Query: Post::where("published", true)->latest()->get().
- Create: Post::create([...]) with $fillable set.
- Relationships: hasMany, belongsTo, belongsToMany.
- Eager load with Post::with("comments") to avoid N+1.
💡 Real-life example: Eloquent is a friendly librarian who fetches rows as books you can read and edit.
EloquentLaravel ORM
$fillableFields allowed for mass assignment
hasManyOne-to-many relationship
with()Eager loads relations