ended4월 2일· 1 sources

Eloquent's increment() Trap: How Unsaved Models Cause Unscoped Database Updates

Eloquent의 increment(), 저장되지 않은 모델에서는 전체 테이블이 업데이트된다

Why it matters

Using increment() on unsaved Eloquent models triggers unscoped UPDATE queries that modify every table row—a silent data corruption risk developers often overlook. This behavior stems from Eloquent's internal `exists` flag, which controls query scoping across many methods. Understanding this relationship is critical for data safety, and developers should ensure models are persisted before calling increment() or opt for firstOrCreate() instead.

1
Sources
+0
24h
Growth
164d
Active
EloquentLaravelincrement()firstOrNew()query scopingpersistence

Sources

Related Issues