C
C
chincharovpc2019-04-20 15:41:27
Laravel
chincharovpc, 2019-04-20 15:41:27

How to set mysql update query in php laravel?

Need instead? write a query to subtract 1 from the count field

DB::table('table')
   ->where('id', $id)
   ->update(
        [
          'count' =>?,
          'updated_at' => now()
         ]
        );
   }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2019-04-20
@chincharovpc

// ...
'count' => \DB::raw('count - 1'),
// ...

J
jazzus, 2019-04-21
@jazzus

With Decrement or in your example

DB::table('table')
   ->where('id', $id)
  ->decrement('count');

updated_at is updated automatically

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question