Reader Stacks

TOPIC

Database Queries & Eloquent

Building queries, joins, and working with Eloquent collections.

Database Transactions in Laravel

Any operation touching more than one table — where a partial failure would leave the data in a genuinely inconsistent state — belongs inside a transaction, not left to run as separate, independent queries.

Laravel Eloquent Where Clauses: A Practical Reference

whereIn, whereNull, orWhere, and a handful of siblings cover almost every filtering need — the one that actually causes bugs is orWhere's grouping behavior when mixed with other conditions.

Querying JSON Columns in Laravel

MySQL and PostgreSQL both support indexing and querying inside a JSON column directly — Eloquent exposes that through arrow syntax and dedicated whereJson* methods, without raw SQL.

Bulk Inserting Rows in Laravel Eloquent

A loop of individual ->save() calls means one query per row — insert() (or upsert() for a merge) does it in one, at the cost of skipping model events and timestamps unless handled manually.

Connecting PHP to MySQL With PDO

PDO is the modern, framework-agnostic way to talk to MySQL from plain PHP — and prepared statements aren't optional if user input touches the query.