Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Tithira's avatar

Setting up Dynamodb connection to Laravel

I am a beginner with NoSQL and trying to connect Dynamodb database to my Laravel App ( v7). I am using https://github.com/renoki-co/dynamodb this package and successfully setup a local environment for the dynamodb. I created a table according to the aws docs.

error: PHP Deprecated: Non-static method App/Models/Record/UserVersion::saveRecord() should not be called statically in Psy Shell code on line 1

Model

use Rennokki\DynamoDb\DynamoDbModel as Model;

class UserVersion extends Model 
{
    public function __construct( array $attributes = [])
    {
        $this->table = 'user';
        parent::__construct($attributes);
    }

    public function saveRecord(User $user){   //the  error reference
        $model = new self();
        $date = now();
        $model->id = 'absd12212';
        $model->user_id = $user->id;
        $model->user = $user;
        $model->save();

        return $model;
    }
}

I tired several methods but throwing out errors. When i list items it is obviously pulling out from the MYSQL db. Since i have installed the above package, am i to create a new database connection driver in config/database.php or what is the best approach for this. I want to know how you save Model data to dynamodb. Any help would be appreciated.

0 likes
1 reply
kitar's avatar
kitar
Best Answer
Level 5

According to the document, you should use a model as same as an eloquent way:

$userVersion = new UserVersion;
$userVersion->id = 'absd12212';
$userVersion->save();

You don't have to provide a custom saveRecord method.

However, when we use Rennokki\DynamoDb\DynamoDbModel, I think we still need to tell the table name and the partition/sort keys to Model. I can't find the way to do that on the document.

This repository was archived, so maybe you could try original one: https://github.com/baopham/laravel-dynamodb

Also, I'm maintaining another Laravel DynamoDB package. Please take a look if you prefer: https://github.com/kitar/laravel-dynamodb

1 like

Please or to participate in this conversation.