← Laravel learning path
Laravel · Module 5 of 10

Eloquent ORM

Work with database records as PHP objects.

📖 Key ideas

  1. Create a model: php artisan make:model Post -m (with migration).
  2. Query: Post::where("published", true)->latest()->get().
  3. Create: Post::create([...]) with $fillable set.
  4. Relationships: hasMany, belongsTo, belongsToMany.
  5. 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