PHPackages                             bluora/laravel-model-json - 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. bluora/laravel-model-json

Abandoned → [hnhdigital-os/laravel-model-json](/?search=hnhdigital-os%2Flaravel-model-json)Library[Database &amp; ORM](/categories/database)

bluora/laravel-model-json
=========================

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

v1.5.0(7y ago)352.1k7MITPHPPHP &gt;=5.6.0

Since Mar 18Pushed 7y agoCompare

[ Source](https://github.com/bluora/laravel-model-json)[ Packagist](https://packagist.org/packages/bluora/laravel-model-json)[ RSS](/packages/bluora-laravel-model-json/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (21)Used By (0)

```
    __                                __    _______ ____  _   __
   / /   ____ __________ __   _____  / /   / / ___// __ \/ | / /
  / /   / __ `/ ___/ __ `/ | / / _ \/ /_  / /\__ \/ / / /  |/ /
 / /___/ /_/ / /  / /_/ /| |/ /  __/ / /_/ /___/ / /_/ / /|  /
/_____/\__,_/_/   \__,_/ |___/\___/_/\____//____/\____/_/ |_/

```

Adds support for the JSON datatype column for models via an object based interface.

[![Latest Stable Version](https://camo.githubusercontent.com/46ef413e51c133ea3335c8d743c5eb8dcfb2ea1486771aac6a0206b763207cce/68747470733a2f2f706f7365722e707567782e6f72672f686e686469676974616c2d6f732f6c61726176656c2d6d6f64656c2d6a736f6e2f762f737461626c652e737667)](https://packagist.org/packages/hnhdigital-os/laravel-model-json) [![Total Downloads](https://camo.githubusercontent.com/ce8f3741314ec2e0645aa9f03a8cb388cb3fb1f18d7007028bacb0ec2d81b629/68747470733a2f2f706f7365722e707567782e6f72672f686e686469676974616c2d6f732f6c61726176656c2d6d6f64656c2d6a736f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/hnhdigital-os/laravel-model-json) [![Latest Unstable Version](https://camo.githubusercontent.com/6221a274b7b0735194aaace76fb3b929150e7a4104635fd891f794218d472928/68747470733a2f2f706f7365722e707567782e6f72672f686e686469676974616c2d6f732f6c61726176656c2d6d6f64656c2d6a736f6e2f762f756e737461626c652e737667)](https://packagist.org/packages/hnhdigital-os/laravel-model-json) [![Built for Laravel](https://camo.githubusercontent.com/ddd4a07bb769306a9338cffde2032c289e4d43d43ac346122709465a47cdff3f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4275696c745f666f722d4c61726176656c2d677265656e2e737667)](https://laravel.com/) [![License](https://camo.githubusercontent.com/ef1065a7b97b03e197ca46b7812463629f801a9d910028e4780c727e6773a0ed/68747470733a2f2f706f7365722e707567782e6f72672f686e686469676974616c2d6f732f6c61726176656c2d6d6f64656c2d6a736f6e2f6c6963656e73652e737667)](https://packagist.org/packages/hnhdigital-os/laravel-model-json)

[![Build Status](https://camo.githubusercontent.com/fd79977202bee75eeb873ea42cff3f6fadbd9ee5f9de6dbe14126cb69045c4e8/68747470733a2f2f7472617669732d63692e6f72672f686e686469676974616c2d6f732f6c61726176656c2d6d6f64656c2d6a736f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/hnhdigital-os/laravel-model-json) [![StyleCI](https://camo.githubusercontent.com/f2c6f5a2e6eb5f8574ec04546dc3286ed1f87e1c4669dc0e541e4c6ba2bf7b66/68747470733a2f2f7374796c6563692e696f2f7265706f732f35333233363938382f736869656c64)](https://styleci.io/repos/53236988) [![Test Coverage](https://camo.githubusercontent.com/5d3776e728866994bb96e7e69128f119503ed6ffaf5b8ad335aef6145c8eecda/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f686e686469676974616c2d6f732f6c61726176656c2d6d6f64656c2d6a736f6e2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/hnhdigital-os/laravel-model-json/coverage) [![Issue Count](https://camo.githubusercontent.com/6795904f64253a238204f559fb08e5095b047605d52910ef853746e298d13a65/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f686e686469676974616c2d6f732f6c61726176656c2d6d6f64656c2d6a736f6e2f6261646765732f69737375655f636f756e742e737667)](https://codeclimate.com/github/hnhdigital-os/laravel-model-json) [![Code Climate](https://camo.githubusercontent.com/48efddcd16c8ec497e4e3486d00d4cc6de36761776086d6bb98117c0bb054a8f/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f686e686469676974616c2d6f732f6c61726176656c2d6d6f64656c2d6a736f6e2f6261646765732f6770612e737667)](https://codeclimate.com/github/hnhdigital-os/laravel-model-json)

This package has been developed by H&amp;H|Digital, an Australian botique developer. Visit us at [hnh.digital](http://hnh.digital).

Install
-------

[](#install)

`$ composer require hnhdigital-os/laravel-model-json ~1.0`

Usage
-----

[](#usage)

### Basic

[](#basic)

The feature is exposed through a trait that allows you to define columns that contain JSON data. When the model is created, it generates methods using the specified column names. You can then get and set the attributes directly.

```
use Bluora\LaravelModelJson\JsonColumnTrait;

class User extends Model
{
    use JsonColumnTrait;

    protected $json_columns = [
        'settings'
    ];
}
```

The JSON column values can then be retrieved or set via an object property.

Let's say we have an array of data stored in the `settings` JSON column:

```
['showProfilePicture' => true, 'options' => ['option1' => 'red']];
```

Getting these values is as simple as:

```
echo $user->settings()->showProfilePicture."\n";
echo $user->settings()->options['option1'];
```

Would output:

```
1
red

```

You can update any variable or add a new one:

```
$user->settings()->options['option2'] = 1;
$user->save();
```

And would update the JSON object with the following array:

```
['showProfilePicture' => true, 'options' => ['option1' => 'red', 'option2' => 1]];
```

Calling `getDirty` with `true` will provide changes using dot notation.

```
print_r($user->getDirty(true));
```

Would output:

```
array(
    'settings' => "{"showProfilePicture":true,"options":{"option1":"red","option2":1}}",
    'settings.options' => array('option2' => 1)
)

```

### NOTE

[](#note)

If you use `findOrNew`, `firstOrNew`, `firstOrCreate`, or the `updateOrCreate` method, you should run the `inspectJson` method before using any JSON columns as the `newFromBuilder` method (which we override) is not called on new model objects.

```
$model = Model::firstOrNew(['name' => 'example']);
$model->inspectJson();
```

### Defaults

[](#defaults)

You can define default values for a json attribute by using the `$json_defaults` property on the model.

You specify the attribute name and default value, if the name does not exist, it will be added at the creation of the object.

```
protected $json_defaults = [
    'settings' => ['showProfilePicture' => 0]
];

```

### Saving changes

[](#saving-changes)

When a save event has been called, the trait sets the original attribute value with the latest JSON encoded value.

If you have used defaults, you can stop these from being saved to the database by setting the option `no_saving_default_values` to true for the specific json column

```
protected $json_options = [
    'settings' => ['no_saving_default_values' => true]
];

```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/hnhdigital-os/laravel-git-info/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Rocco Howard](https://github.com/therocis)
- [All Contributors](https://github.com/hnhdigital-os/laravel-git-info/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/hnhdigital-os/laravel-git-info/blob/master/LICENSE) for more information.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 97.5% of commits — single point of failure

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

Recently: every ~116 days

Total

19

Last Release

2696d ago

PHP version history (2 changes)v1.0PHP &gt;=5.4.0

v1.4.9PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5270e3a3d1add4e39f12dfde3ce549999a26f759d7128056083ab07f475259f2?d=identicon)[bluora](/maintainers/bluora)

---

Top Contributors

[![RoccoHoward](https://avatars.githubusercontent.com/u/227896?v=4)](https://github.com/RoccoHoward "RoccoHoward (119 commits)")[![evgenmedia](https://avatars.githubusercontent.com/u/19681569?v=4)](https://github.com/evgenmedia "evgenmedia (3 commits)")

---

Tags

jsonlaraveleloquentilluminateschemalessschema-free

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bluora-laravel-model-json/health.svg)

```
[![Health](https://phpackages.com/badges/bluora-laravel-model-json/health.svg)](https://phpackages.com/packages/bluora-laravel-model-json)
```

###  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)
