Created
December 5, 2022 19:20
-
-
Save Vigowebs/ead01eb7d6bb0ff1660bad251ac2bff3 to your computer and use it in GitHub Desktop.
Increments and Decrements in Eloquent Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ❌ | |
$product = Product::find($production_id); | |
$product->stock++; | |
$product->save(); | |
// ✔️ | |
Product::find($production_id)->increment('stock'); // +1 | |
Product::find($production_id)->decrement('stock'); // -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment