What I Found Inside Eloquent's increment()
I was experimenting with firstOrNew() and increment() in my Laravel lab and ended up running a query I did not expect. I was building a small inventory tracker to see how these two methods interact...

Source: DEV Community
I was experimenting with firstOrNew() and increment() in my Laravel lab and ended up running a query I did not expect. I was building a small inventory tracker to see how these two methods interact. The idea is that when a shipment comes in, find the product and bump its stock count. If it doesn't exist yet, a new record gets created first. firstOrNew() seemed like the right tool, one call, handles both cases. If you've ever used these two together, this is worth knowing. $incomingShipment = $inventoryItem::firstOrNew(['product_name' => 'Metallic Coffee Mug']); $incomingShipment->increment('stock_count', 50); "Metallic Coffee Mug" wasn't in the database. So firstOrNew() returned a new unsaved model instance — no id, no primary key, and $model->exists = false. Then I called increment(). What the query log showed I had three items in the table going in: product_name stock_count macbook air M4 10 DELL monitor 5 Varmilo Keyboard 3 After increment('stock_count', 50), every single r