Reader Stacks

TOPIC

Database Queries & Eloquent

Building queries, joins, and working with Eloquent collections.

Storing Arrays and JSON in Laravel Eloquent (Casts)

A cast is what turns a raw JSON text column into a working PHP array automatically on every read and write — without one, Eloquent hands back and expects a plain JSON string instead.

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.

Writing Raw SQL Queries in Laravel Safely

When a raw query is actually justified over Eloquent, and why parameter binding — not string concatenation — is the difference between a raw query and a SQL injection bug.

GROUP BY and HAVING in Laravel Eloquent

GROUP BY collapses rows into per-group summaries; HAVING filters those summaries afterward — the key distinction from WHERE, which filters individual rows before any grouping happens.

Multiple Database Connections in Laravel

A second, separate database — legacy data, a read replica, a reporting warehouse — is configured as another named connection, and a model or query explicitly opts into using it.