PHPackages                             digitalmanagerguru/laravel-json-fields - 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. digitalmanagerguru/laravel-json-fields

ActiveLibrary

digitalmanagerguru/laravel-json-fields
======================================

A package to work with database JSON fields with laravel eloquent Models.

2.0.0(1y ago)03.1k↓20%1[1 PRs](https://github.com/digitalmanagerguru/laravel-json-fields/pulls)MITPHPPHP &gt;=8.3.0

Since Jan 28Pushed 1y agoCompare

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

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

Laravel Json Fields (Laravel Package)
=====================================

[](#laravel-json-fields-laravel-package)

[![GitHub tag](https://camo.githubusercontent.com/36b130e806b1529f7675aa0e36799dcb05bd7d3b638c0d84b1308b75d05206df/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f6469676974616c6d616e61676572677572752f6c61726176656c2d6a736f6e2d6669656c64733f696e636c7564655f70726572656c65617365733d26736f72743d73656d76657226636f6c6f723d626c7565)](https://github.com/digitalmanagerguru/laravel-json-fields/releases/)[![License](https://camo.githubusercontent.com/d6bc2b26794002c24d023acaab01b6dbb953c57ab9cb80ba5b8aa2f2bd5de99a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c7565)](#license)[![issues - laravel-json-fields](https://camo.githubusercontent.com/b5c27b1c13b33e242ac317ec55a978c4fe9f40159ca57eb0a121a1c0f1632765/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6469676974616c6d616e61676572677572752f6c61726176656c2d6a736f6e2d6669656c6473)](https://github.com/digitalmanagerguru/laravel-json-fields/issues)

Laravel JSON Fieds is simple and clean way to work with Eloquent JSON Fieds with Dot Notation.

Version Compatibility
---------------------

[](#version-compatibility)

LaravelLaravel JSON Fields12.x\[2.x\]10.x, 11.X\[1.x\]Installation
------------

[](#installation)

To install, run `composer require digitalmanagerguru/laravel-json-fields`.

What does it support?
---------------------

[](#what-does-it-support)

- Check if a key exists
- Check if the field is empty
- Check if a key contains a value
- Get a value from a key
- Set a value in a key
- Merge two arrays in a key
- Delete values from a key
- Get all the content from the field decoded as an associative array
- Set all the content from and encoded associative array as JSON
- Get the JSON field name
- Add a log entry to the field

Usage
-----

[](#usage)

### Importing

[](#importing)

On a Laravel Eloquent Model import the PHP Interface `Digitalmanagerguru\LaravelJsonFields\Contracts\HasJsonField` then import the PHP Trait `Digitalmanagerguru\LaravelJsonFields\Traits\HasJsonFieldTrait`, like:

```
...
use Digitalmanagerguru\LaravelJsonFields\Contracts\HasJsonField;
use Digitalmanagerguru\LaravelJsonFields\Traits\HasJsonFieldTrait;

class User extends Authenticatable implements HasJsonField
{
    use HasJsonFieldTrait;

    ...
}

```

### Changing the default field name

[](#changing-the-default-field-name)

By default it maps a field called `metadata`, it can be changed by declaring an attribute called `$jsonField` like:

```
class ... implements HasJsonField
{
    use HasJsonFieldTrait;

    ...
    protected $jsonField = 'settings';

    ...

}

```

### Methods Usage

[](#methods-usage)

#### Check if a key exists (`hasJsonKey($value)`)

[](#check-if-a-key-exists-hasjsonkeyvalue)

`$user->hasJsonKey("addresses") //boolean`

#### Check if the field is empty (`hasJsonField()`)

[](#check-if-the-field-is-empty-hasjsonfield)

`$user->hasJsonField() //boolean`

#### Check if a key contains a value (`isEmptyJsonKeyValue($key)`)

[](#check-if-a-key-contains-a-value-isemptyjsonkeyvaluekey)

`$user->isEmptyJsonKeyValue("addresses.default") //boolean`

#### Get a value from a key (`getJsonKeyValue($key, $default = null)`)

[](#get-a-value-from-a-key-getjsonkeyvaluekey-default--null)

`$user->getJsonKeyValue("addresses.default", []) //any`

#### Set a value in a key (`setJsonKeyValue($key, $value)`)

[](#set-a-value-in-a-key-setjsonkeyvaluekey-value)

`$user->setJsonKeyValue("addresses.default", ["street" => "...."]) //void`

#### Merge two arrays in a key (`mergeJsonKeyValue($key, array $value)`)

[](#merge-two-arrays-in-a-key-mergejsonkeyvaluekey-array-value)

`$user->mergeJsonKeyValue("addresses", ["default" => [...]]) //void`

#### Delete values from a key (`forgetJsonKey($key)`)

[](#delete-values-from-a-key-forgetjsonkeykey)

`$user->forgetJsonKey("addresses") //void`or `$user->forgetJsonKey(["addresses", "is_active"]) //void`

#### Get all the content from the field decoded as an associative array (`getJsonFieldValue()`)

[](#get-all-the-content-from-the-field-decoded-as-an-associative-array-getjsonfieldvalue)

`$user->getJsonFieldValue() //array`

#### Set all the content from and encoded associative array as JSON (`setJsonFieldValue(array $value)`)

[](#set-all-the-content-from-and-encoded-associative-array-as-json-setjsonfieldvaluearray-value)

`$user->setJsonFieldValue([...]) //void`

#### Get the JSON field name (`getJsonFieldName()`)

[](#get-the-json-field-name-getjsonfieldname)

`$user->getJsonFieldName() //string`

#### Add a log entry to the field (`addLog($value)`)

[](#add-a-log-entry-to-the-field-addlogvalue)

`$user->addLog("Changed the is_active status") //string`

License
-------

[](#license)

Laravel JSON Fields is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

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

[](#contributing)

Please report any issue you find in the issues page. Pull requests are more than welcome.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance43

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~9 days

Total

4

Last Release

447d ago

Major Versions

1.1.0 → 2.0.02025-02-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/83672fbc6b14f467ab53f557471717ff3929b0dfa01b4bc37ec42a769da0e068?d=identicon)[RicardoRodriguesGuru](/maintainers/RicardoRodriguesGuru)

---

Top Contributors

[![RicardoRodriguesGuru](https://avatars.githubusercontent.com/u/57721219?v=4)](https://github.com/RicardoRodriguesGuru "RicardoRodriguesGuru (14 commits)")

---

Tags

composercomposer-packagelaravelpackage

### Embed Badge

![Health badge](/badges/digitalmanagerguru-laravel-json-fields/health.svg)

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

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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