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.
GUIDES
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.
whereBetween() handles the basic case cleanly — the real detail to get right is making sure the end date's time component actually includes the whole day, not just midnight.
toSql(), getBindings(), and DB::listen() — the difference between seeing the query shape and seeing the actual query that ran, bindings included.
count(), isEmpty(), isNotEmpty(), and the N+1-query mistake people make trying to "optimize" an empty check on an Eloquent relationship.
inRandomOrder() genuinely shuffles at the database level for a small table, but it becomes a real performance concern once a table grows into the millions of rows — worth knowing before reaching for it blindly.
$request->json() and $request->input() end up reading the exact same parsed body for a JSON request — the difference only matters once the client sends something Laravel doesn't already parse automatically.
Four common schema changes on an existing table — adding a column, giving it a default, indexing it, and adding an enum column — plus the one package they all quietly depend on for SQLite.
A migration is a version-controlled, reversible description of one schema change — the file, the up()/down() methods, and the commands that actually apply or undo it.
Eloquent's array and json casts handle the encoding and decoding transparently — a model attribute reads and writes as a real PHP array, with the JSON conversion happening invisibly underneath.
inRandomOrder() and lastInsertId() solve two small, specific problems that come up often enough to be worth knowing by name rather than working out from scratch each time.
A modern Laravel API separates routes, validation, authorization, persistence, resources, authentication and tests instead of returning raw models from controllers.
Three ways to call an external API from PHP or Laravel — raw cURL, file_get_contents with a stream context, and Laravel's own Http facade, which is the one worth reaching for in a Laravel app.