3

I have this query

 DB::table('product_options')
        ->where('product_id', $id)
        ->where('size', $selected_size)
        ->update(array('stock' => WHAT TO PUT HERE));

In the update part where I've put WHAT TO UPDATE, what should I put here to decrease the number by 1?

1 Answer 1

6

Use the decrement method. http://laravel.com/docs/4.2/queries#updates

 DB::table('product_options')
        ->where('product_id', $id)
        ->where('size', $selected_size)
        ->decrement('stock');
Sign up to request clarification or add additional context in comments.

3 Comments

So I dont need the update method then just decrement? @slapyo
Yup, check out the link. You can pass the value you want to decrease by and you can also pass other columns to update if you need.
Yep always forgot about these little extra bits in Laravel, cheers dude

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.