Eloquent Secrets

Advanced Eloquent features and patterns that go beyond the basics.

Intermediate Since 10.x

Model::withoutTimestamps()

Execute operations without touching the updated_at column, useful for bulk imports and data migrations.

Database
Advanced Since 10.x

DB::whenQueryingForLongerThan()

Get notified when your cumulative database query time exceeds a threshold during a single request.

Database Performance Debugging
Intermediate Since 8.x

Model::withoutEvents()

Silence all model events within a closure — perfect for seeding, imports, and data migrations where observers would cause side-effects.

Database Events
Intermediate Since 8.x

Model::toQuery()

Convert an Eloquent Collection back into a query builder scoped to those exact model IDs — bridging collections and queries.

Collections Database
Intermediate Since 8.x

Model::withAggregate()

Load aggregated values from related models as attributes — count, sum, min, max, avg — in a single query without loading the relation.

Database Performance