Skip to content

Instantly share code, notes, and snippets.

@Vigowebs
Created December 5, 2022 19:20
Show Gist options
  • Save Vigowebs/ead01eb7d6bb0ff1660bad251ac2bff3 to your computer and use it in GitHub Desktop.
Save Vigowebs/ead01eb7d6bb0ff1660bad251ac2bff3 to your computer and use it in GitHub Desktop.
Increments and Decrements in Eloquent Laravel
// ❌
$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