我如何更新动力模型

时间:2018-10-09 07:24:03

标签: php laravel amazon-web-services model amazon-dynamodb

我正在尝试使用

在laravel中更新我的dynamodb项目。

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

这是我的模特;使用php artisan tinker;

我要更新的属性是“地图”类型。

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",
    ],
}

当我这样做时。模型未更新

$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;

2 个答案:

答案 0 :(得分:1)

您可以更新Eloquent对象中的map属性,然后将其保存到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;

编辑:修复了代码

答案 1 :(得分:0)

您可以使用updateAsync,更新不会立即生效

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