D
D
DocTypeMaster2021-02-10 15:05:36
Laravel
DocTypeMaster, 2021-02-10 15:05:36

How to increase value in base by 1?

There was a need to update the database, and add + 1 to one field (well, or the value that I will change dynamically)

$book = CardModel::where('number_card', $id)->first();
        $ff = 1;
        $book->count_cup ++;
        $book -> save();


This is how it adds +1 every round of the query, but if I write + 1 or + some variable it won't add (
Here are my migrations

$table->id();
$table->string('number_card') ;
$table->integer('count_cup')->default('0');
$table->string('coffee_bar_name')->default('Test');

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Sarvarov, 2021-02-11
@megakor

$model->increment();

0
0xD34F, 2017-09-06
@alex-prog

It doesn't work because the event handler is not set via jQuery. Hence the solution - to create and dispatch the event manually.
Instead we write like this:$('select').val('ru').trigger('click');

$('select').val('ru')[0].dispatchEvent(new Event('change'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question