So I have a user structure like so:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('username');
$table->text('phone');
$table->string('address');
$table->string('city');
$table->string('state');
$table->string('country');
$table->string('postal');
$table->string('email')->unique();
$table->string('password');
$table->string('google2fa_secret');
$table->text('balance');
$table->rememberToken();
$table->timestamps();
});
Now, I am storing values in the 'balance' collumn like so
{
"usd": 10,
"gbp": 10,
"eur": 10
}
How can I edit for example usd value but keep the others in the array with attributes?
How I am getting the attributes:
/**
* Get the user's balance
*
* @return decimal
*/
public function getBalanceAttribute()
{
return json_decode( $this->attributes['balance'] );
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire