Garine
Garine

Reputation: 604

how can I update a dynamodb model

I'm trying to update my dynamodb item in laravel using

https://github.com/baopham/laravel-dynamodb

this is my model; using php artisan tinker;

the attribute that I want to update is of 'map' type.

App\DynamoConfiguration {#1873
    op_city_id: 1,
    created_at: "2018-10-08T11:02:42+00:00",
    updated_at: "2018-10-08T11:11:26+00:00",
    info: [
        "shopper_logs_enabled" => "1",
    ],
}

when I do this. the model is not updated

$dynamo_configuration = DynamoConfiguration::where('op_city_id', 1)->first();
$info = $dynamo_configuration->info;
$info['shopper_logs_enabled'] = '0';
$dynamo_configuration->update(["info" => $info]);
return $dynamo_configuration;

Upvotes: 1

Views: 887

Answers (2)

Sahil
Sahil

Reputation: 468

You can update the map attribute in the Eloquent Object and then save it to DynamoDB.

$dynamo_configuration = DynamoConfiguration::where('op_city_id', 1)->first();
$info = $dynamo_configuration->info;
$info['shopper_logs_enabled'] = '0';
$dynamo_configuration->info = $info;
$dynamo_configuration->save();
return $dynamo_configuration;

Edit: Fixed the code

Upvotes: 1

sundb
sundb

Reputation: 490

You can use updateAsync, update will not take effect immediately

// update asynchronously and wait on the promise for completion.
$model->updateAsync($attributes)->wait();

Upvotes: 0

Related Questions