PHPackages                             quankim/laravel-dynamodb-eloquent-syntax - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. quankim/laravel-dynamodb-eloquent-syntax

ActiveLibrary[Database &amp; ORM](/categories/database)

quankim/laravel-dynamodb-eloquent-syntax
========================================

Custom Eloquent syntax for DynamoDB from https://github.com/baopham/laravel-dynamodb

1.1(8y ago)2324MITPHP

Since Jul 10Pushed 8y agoCompare

[ Source](https://github.com/quanvhframgia/laravel-dynamodb-eloquent-syntax)[ Packagist](https://packagist.org/packages/quankim/laravel-dynamodb-eloquent-syntax)[ RSS](/packages/quankim-laravel-dynamodb-eloquent-syntax/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

laravel-dynamodb-eloquent-syntax
================================

[](#laravel-dynamodb-eloquent-syntax)

Eloquent syntax for DynamoDB

Custom from

[![Latest Stable Version](https://camo.githubusercontent.com/8fbe86ae1b6f274d7efae9293dab388e6b078f82177cf60384cfa5b4d0f6fb01/68747470733a2f2f706f7365722e707567782e6f72672f62616f7068616d2f64796e616d6f64622f762f737461626c65)](https://packagist.org/packages/baopham/dynamodb)[![Total Downloads](https://camo.githubusercontent.com/1d75e034de9f69bcfd1816c091bc095a495c26ca0c21757cc4a850b0accaea4f/68747470733a2f2f706f7365722e707567782e6f72672f62616f7068616d2f64796e616d6f64622f646f776e6c6f616473)](https://packagist.org/packages/baopham/dynamodb)[![Latest Unstable Version](https://camo.githubusercontent.com/29d275ea5bc54a0d450a7943d5a749232f08c626f4dfcec5e7a513cc7bbe1154/68747470733a2f2f706f7365722e707567782e6f72672f62616f7068616d2f64796e616d6f64622f762f756e737461626c65)](https://packagist.org/packages/baopham/dynamodb)[![License](https://camo.githubusercontent.com/009b4a2ca8a011ae0b60c9aa2db2220b7060a31b8cb5497add740c3cd0c4ad92/68747470733a2f2f706f7365722e707567782e6f72672f62616f7068616d2f64796e616d6f64622f6c6963656e7365)](https://packagist.org/packages/baopham/dynamodb)

Supports all key types - primary hash key and composite keys.

> For advanced users only. If you're not familiar with Laravel, Laravel Eloquent and DynamoDB, then I suggest that you get familiar with those first.

> **Breaking Changes** for v0.4
>
> - If you're using v0.3 and below, please see [here](./README.v0.3.md)
> - To upgrade to v0.4, please see the [migration note]('./MIGRATION.md')

- [Install](#install)
- [Usage](#usage)
- [Indexes](#indexes)
- [Composite Keys](#composite-keys)
- [Test](#test)
- [Requirements](#requirements)
- [Todo](#todo)
- [License](#license)
- [Author and Contributors](#author-and-contributors)

Install
-------

[](#install)

- Composer install ```
    ```

 composer require quankim/laravel-dynamodb-eloquent-syntax ```

- Install service provider:

    ```
    // config/app.php

    'providers' => [
        ...
          QuanKim\DynamoDbEloquentSyntax\DynamoDbServiceProvider::class,
        ...
    ];
    ```
- Put DynamoDb config in `config/aws.php`:

    ```
    // config/aws.php
    ...
    'credentials' => [
        'key'    => env('AWS_ACCESS_KEY_ID', ''),
        'secret' => env('AWS_SECRET_ACCESS_KEY', ''),
    ],
    'region' => env('AWS_REGION', 'us-east-1'),
    'version' => 'latest',
    'endpoint' => env('AWS_ENDPOINT', ''),
    ...
    ```

Usage
-----

[](#usage)

- Extends your model with `QuanKim\DynamoDbEloquentSyntax\DynamoDbModel`, then you can use Eloquent methods that are supported. The idea here is that you can switch back to Eloquent without changing your queries.

Supported methods:

```
// find and delete
$model->find();
$model->delete();

// Using getIterator(). If 'key' is the primary key or a global/local index and the condition is EQ, will use 'Query', otherwise 'Scan'.
$model->where('key', 'key value')->get();

$model->where(['key' => 'key value']);
// Chainable for 'AND'. 'OR' is not supported.
$model->where('foo', 'bar')
    ->where('foo2', '!=' 'bar2')
    ->get();

// Using scan operator, not too reliable since DynamoDb will only give 1MB total of data.
$model->all();

// Basically a scan but with limit of 1 item.
$model->first();

// update
$model->update($attributes);

$model = new Model();
// Define fillable attributes in your Model class.
$model->fillableAttr1 = 'foo';
$model->fillableAttr2 = 'foo';
// DynamoDb doesn't support incremented Id, so you need to use UUID for the primary key.
$model->id = 'de305d54-75b4-431b-adb2-eb6b9e546014'
$model->save();

// chunk
$model->chunk(10, function ($records) {
    foreach ($records as $record) {

    }
});

// Additional
// Where in
$model->where('id', 'in', [])
// Sub query
$model->where(function($q) {
    $q->where('id', 1)
        ->where('name', 'contains', 'a');
})->orWhere('email', 'contains', 'abc'));

// Delete all
$model->where('id', 'in', [1,2,3])->deleteAll();
// Increment/ Decrement a column
$model->increment('view_count', 1);
$model->decrement('total_product', 1);

// Paginate
$model->paginate([], $limit, $lastEvaluatedKey);
```

- Or if you want to sync your DB table with a DynamoDb table, use trait `QuanKim\DynamoDbEloquentSyntax\ModelTrait`, it will call a `PutItem` after the model is saved.

Indexes
-------

[](#indexes)

If your table has indexes, make sure to declare them in your model class like so

```
/**
 * Indexes.
 * [
 *     'simple_index_name' => [
 *          'hash' => 'index_key'
 *     ],
 *     'composite_index_name' => [
 *          'hash' => 'index_hash_key',
 *          'range' => 'index_range_key'
 *     ],
 * ].
 *
 * @var array
 */
protected $dynamoDbIndexKeys = [
    'count_index' => [
        'hash' => 'count'
    ],
];
```

Note that order of index matters when a key exists in multiple indexes.
For example, we have this

```
$this->where('user_id', 123)->where('count', '>', 10)->get();
```

with

```
protected $dynamoDbIndexKeys = [
    'count_index' => [
        'hash' => 'user_id',
        'range' => 'count'
    ],
    'user_index' => [
        'hash' => 'user_id',
    ],
];
```

will use `count_index`.

```
protected $dynamoDbIndexKeys = [
    'user_index' => [
        'hash' => 'user_id',
    ],
    'count_index' => [
        'hash' => 'user_id',
        'range' => 'count'
    ]
];
```

will use `user_index`.

Composite Keys
--------------

[](#composite-keys)

To use composite keys with your model:

- Set `$compositeKey` to an array of the attributes names comprising the key, e.g.

```
protected $primaryKey = ['customer_id'];
protected $compositeKey = ['customer_id', 'agent_id'];
```

- To find a record with a composite key

```
$model->find(['id1' => 'value1', 'id2' => 'value2']);
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity64

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3229d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13218211?v=4)[Mr.Don't Ask](/maintainers/quanvh)[@quanvh](https://github.com/quanvh)

---

Tags

laravelawsdynamodb

### Embed Badge

![Health badge](/badges/quankim-laravel-dynamodb-eloquent-syntax/health.svg)

```
[![Health](https://phpackages.com/badges/quankim-laravel-dynamodb-eloquent-syntax/health.svg)](https://phpackages.com/packages/quankim-laravel-dynamodb-eloquent-syntax)
```

###  Alternatives

[aws/aws-sdk-php-laravel

A simple Laravel 9/10/11/12/13 service provider for including the AWS SDK for PHP.

1.7k35.6M75](/packages/aws-aws-sdk-php-laravel)[baopham/dynamodb

Eloquent syntax for DynamoDB

4975.7M6](/packages/baopham-dynamodb)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[kitar/laravel-dynamodb

A DynamoDB based Eloquent model and Query builder for Laravel.

193675.3k1](/packages/kitar-laravel-dynamodb)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
