Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
How to decrement a column value in Laravel

This is the query i am using:

$number = DB::table('products')->where('id', '=', $product->id)->update(['quantity' => 'quantity', '-', 1 ]);

Please help me with the right syntax. I want to subtract 1 from the current value of quantity column. Thanks

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You may use decrement method for this;

The query builder also provides convenient methods for incrementing or decrementing the value of a given column. This is a shortcut, providing a more expressive and terse interface compared to manually writing the update statement.

DB::table('products')->where('id', $product->id)->decrement('quantity');
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!