A
A
Artem00712018-03-09 13:35:40
Laravel
Artem0071, 2018-03-09 13:35:40

How to update json?

The model has param and value(json) fields.
{'value': {'total': 100, 'current': 10} }
I need to increase the current value.
So I do it like this:

$taxation = Taxation::where('param', 'BALANCE')->first()->value;
                $current = $taxation['current']; // текущее значение
                $taxation['value->current'] = $current + $someValue;
                $taxation->save();

I also know that you can use DB::raw(), but it doesn't work:
System::where('param', 'BALANCE')->update([
  'value->current' => 3 // вот тут получается добавить только "статичные данные", то есть не получится узнать текущее значение и прибавить к нему что то
  'value->current' => DB::raw('value->current + 3') // работать не будет
]);

Is there any way to fix the last option? Or update works only as in the first option?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question