PHPackages                             arm092/new-dialect - 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. arm092/new-dialect

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

arm092/new-dialect
==================

Provides JSON datatype support for the Eloquent ORM

1.1.0(4y ago)061MITPHPPHP &gt;=5.4.0

Since Oct 17Pushed 4y agoCompare

[ Source](https://github.com/arm092/dialect)[ Packagist](https://packagist.org/packages/arm092/new-dialect)[ RSS](/packages/arm092-new-dialect/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (11)Used By (0)

Dialect
=======

[](#dialect)

[![Build Status](https://camo.githubusercontent.com/73ae9ea8081b582acc5e3e3c74f89a07892f66dbe5d75156bbea7ef66c980b75/68747470733a2f2f696d672e736869656c64732e696f2f6170707665796f722f6275696c642f61726d3039322f6469616c6563743f7374796c653d666f722d7468652d6261646765)](https://img.shields.io/appveyor/build/arm092/dialect) [![Code Coverage](https://camo.githubusercontent.com/d596f55d5b1836150e22be6bf4de90139fe86c1d1925fab3366101170df0d5ca/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f61726d3039322f6469616c6563742f6d61737465723f7374796c653d666f722d7468652d6261646765)](https://img.shields.io/scrutinizer/coverage/g/arm092/dialect/master) [![Test Coverage](https://camo.githubusercontent.com/df9c12b425dcdb32afcf77f6dd49575be62fab72efb3d0eeeb65db422ea336f8/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f64617272796c6b75686e2f6469616c6563742f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/darrylkuhn/dialect)

Dialect provides JSON datatype support for the [Eloquent ORM](http://laravel.com/docs/eloquent). At this point this implementation is pretty bare bones and has been demonstrated to work with PostgreSQL and MySQL. There are lots of opportunities to enhance and improve. If you're interested in contributing please submit merge/pull requests.

Installation
------------

[](#installation)

`composer require arm092/dialect`

Usage
-----

[](#usage)

### The Basics

[](#the-basics)

The feature is exposed through a trait called which allows you to define attributes on the model which are of the json datatype. When the model is read in it will parse the JSON document and set up getters and setters for each top level attribute making it easy to interact with the various attributes within the document. For example we could create a Photos model like this:

```
class Photo extends Eloquent
{
    use Eloquent\Dialect\Json;
    protected $jsonColumns = ['json_data'];
}
```

And then this:

```
$attr = json_decode($photo->json_data);
$attr->key = $value;
$photo->json_data = json_encode($attr);
```

becomes this:

```
$photo->key = value;
```

Also when calling the toArray() method the attributes are moved to the top level and the 'json\_attributes' column is hidden. This essentially hides away the fact that you're using the json datatype and makes it look like we're working with attributes directly.

### Relations

[](#relations)

You can also establish relationships on a model like this (only supported in PostgreSQL):

```
public function user()
{
    return $this->hasOne( 'User', 'id', "json_data->>'user_id'" );
}
```

### Structure Hinting

[](#structure-hinting)

Sometimes you may have an empty or partially populated record in which case the trait cannot automatically detect and create getters/setters, etc... When getting or setting an attribute not previously set in the JSON document you'll get an exception. You have two choices to deal with this. You can hint at the full structure as in the example below:

```
class Photo extends Eloquent
{
    use Eloquent\Dialect\Json;
    protected $jsonColumns = ['json_data'];

    public function boot()
    {
        parent::boot();
        $this->hintJsonStructure( 'json_data', '{"foo":null}' );
    }
}
```

Once you create a hint you will be able to make calls to get and set json attributes e.g. `$photo->foo = 'bar';` regardless of whether or not they are already defined in the underlying db record. Alternatly if you prefer not to hint structures then you may call `setJsonAttribute()`. For example if you defined a json column called "json\_data" and wanted to set an attribute called 'fizz' so you could call:

```
$photo->setJsonAttribute( 'json_data', 'fizz', 'buzz' );
```

### Showing/Hiding Attributes

[](#showinghiding-attributes)

One of the aims of the project is to make json attributes "first class" citizens of the model. This means by default we add the attributes to the models appends array so that when you call `$model->toArray()` or `$model->toJson()` the attribute shows up as a part of the structure like a normal attribute. By default we also hide away the json column holding the underlying data. Both of these settings can be changed using the `showJsonColumns()` and `showJsonAttributes()` as shown below:

```
class Photo extends Eloquent
{
    use Eloquent\Dialect\Json;
    protected $jsonColumns = ['json_data'];

    public function boot()
    {
        parent::boot();
        $this->showJsonColumns(true);
        $this->showJsonAttributes(false);
    }
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~266 days

Recently: every ~502 days

Total

9

Last Release

1724d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/164d92f2197474470e0481c423db3b73140c82abdae8a9427e0dfba087e94bf3?d=identicon)[arm092](/maintainers/arm092)

---

Top Contributors

[![darrylkuhn](https://avatars.githubusercontent.com/u/3458313?v=4)](https://github.com/darrylkuhn "darrylkuhn (6 commits)")[![arman-devolon](https://avatars.githubusercontent.com/u/113534144?v=4)](https://github.com/arman-devolon "arman-devolon (5 commits)")[![danielnv18](https://avatars.githubusercontent.com/u/3136353?v=4)](https://github.com/danielnv18 "danielnv18 (1 commits)")[![kblais](https://avatars.githubusercontent.com/u/1931954?v=4)](https://github.com/kblais "kblais (1 commits)")[![mfos239](https://avatars.githubusercontent.com/u/5534308?v=4)](https://github.com/mfos239 "mfos239 (1 commits)")[![ravloony](https://avatars.githubusercontent.com/u/1112704?v=4)](https://github.com/ravloony "ravloony (1 commits)")

---

Tags

jsonlaraveleloquentilluminateschemalessschema-free

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/arm092-new-dialect/health.svg)

```
[![Health](https://phpackages.com/badges/arm092-new-dialect/health.svg)](https://phpackages.com/packages/arm092-new-dialect)
```

###  Alternatives

[darrylkuhn/dialect

Provides JSON datatype support for the Eloquent ORM

130245.3k](/packages/darrylkuhn-dialect)[hnhdigital-os/laravel-model-json

Provides JSON column support for for Laravel's Eloquent Model.

351.8k](/packages/hnhdigital-os-laravel-model-json)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)[mpyw/laravel-local-class-scope

A tiny macro that reuse a global scope class as a local scope

24102.6k](/packages/mpyw-laravel-local-class-scope)[cviebrock/eloquent-typecast

Trait for Eloquent models to force type-casting on retrieved values

2468.0k](/packages/cviebrock-eloquent-typecast)[omalizadeh/laravel-query-filter

A laravel package for resource filtering via request query string

163.0k](/packages/omalizadeh-laravel-query-filter)

PHPackages © 2026

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