Stage 2 · Lesson 9 of 10
PDO, Eloquent and migrations
Start with PDO, PHP's built-in database layer. You write a with , run it with your values and fetch the rows. That shows you exactly what does for you later.
Eloquent is 's ORM. Each model maps to a table. Relationships are methods such as hasMany and belongsTo.
Queries read like Order::where('status', 'paid')->latest()->get(). Schema changes live in classes. You create them with php artisan make:migration and apply them with php artisan migrate, which records what has run. Guard against mass assignment (users setting fields they should not) with $fillable.
Common trapediting an old migration after it has run in production, or running php artisan migrate:fresh anywhere near real data, since it drops every table.
A question to check yourself, an AI practice session and 3 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Relational Database Design and Modeling
Design Gurus · Intermediate · $98 one-time
The modelling and normalisation decisions that stay with a codebase for years
- CourseFreeCS50's Introduction to Databases with SQL
Harvard University · Beginner
Free course from querying through schema design, indexes, transactions and scaling
Practise
Also worth your time
- Database Indexing Explained: B-Tree, Hash, Bitmap, R-Tree, and When to Use Each (opens in a new tab)Read
B-tree and composite indexes, plus the leftmost-prefix rule that trips people up
What sits under your queries: storage engines, transactions and isolation levels