Answer the question
In order to leave comments, you need to log in
How to edit JSON?
I have a User field inside which there is a column balance (type TEXT ) , which should store json data by type
{"BTC": {
"Bitcoin_wallet": "NULL",
"Bitcoin_balance": "0.00"
},
"ETH": {
"Ether_wallet": "NULL",
"Ether_balance": "0.00"
}
}
$in['balance']=$user->balance;
$in['balance'] = [
$user->balance->BTC->Bitcoin_wallet => $request->Bitcoin_wallet,
$user->balance->ETH->Ether_wallet => $request->Ether_wallet
]
Answer the question
In order to leave comments, you need to log in
1. It is better to use not TEXT but JSON
2. There is a mention of this in the documentation. To set nested values:
2.1 use arrow notation
$casts = [
'balance' => 'array',
];
$user->balance['BTS->Bitcoin_wallet'] = '';
$casts = [
'balance' => AsArrayObject::class,
];
$user->balance['BTS']['Bitcoin_wallet'] = '';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question