Reader Stacks

TOPIC

Database Queries & Eloquent

Building queries, joins, and working with Eloquent collections.

INSERT...SELECT in MySQL: Copying Rows Between Tables

Copying rows from one table into another as a SELECT-then-loop-INSERT operation means one query per row — INSERT...SELECT does the whole copy as a single statement, entirely inside the database.

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.

How to Use LEFT JOIN in Laravel Eloquent

leftJoin() syntax, why it returns null columns instead of dropping rows, and the specific case where it behaves differently from a whereHas() relationship query.