PHPackages                             aidynmakhataev/eloquent-json-macros - 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. aidynmakhataev/eloquent-json-macros

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

aidynmakhataev/eloquent-json-macros
===================================

A Laravel Eloquent Builder macros for MySQL JSON functions

1.0.0(7y ago)101225[1 PRs](https://github.com/AidynMakhataev/eloquent-json-macros/pulls)MITPHP

Since Jul 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/AidynMakhataev/eloquent-json-macros)[ Packagist](https://packagist.org/packages/aidynmakhataev/eloquent-json-macros)[ Docs](https://github.com/AidynMakhataev/eloquent-json-macros)[ RSS](/packages/aidynmakhataev-eloquent-json-macros/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (2)Used By (0)

Laravel Eloquent JSON Macros
============================

[](#laravel-eloquent-json-macros)

This package helps you to use MySQL JSON functions in Eloquent style and as helper functions.

[![Latest Stable Version](https://camo.githubusercontent.com/8608253729792369ee57d349bb4af62326a50a30e6654473df28c9b5df06d753/68747470733a2f2f706f7365722e707567782e6f72672f616964796e6d616b6861746165762f656c6f7175656e742d6a736f6e2d6d6163726f732f762f737461626c65)](https://packagist.org/packages/aidynmakhataev/eloquent-json-macros)[![Latest Unstable Version](https://camo.githubusercontent.com/08165176b3ce0d1696931d09b35e4adb8156a04271f7920dc6003b77c4593c6b/68747470733a2f2f706f7365722e707567782e6f72672f616964796e6d616b6861746165762f656c6f7175656e742d6a736f6e2d6d6163726f732f762f756e737461626c65)](https://packagist.org/packages/aidynmakhataev/eloquent-json-macros)[![](https://camo.githubusercontent.com/c82cc6e31379e062793f132348f08698591f47b22e1bf18db3978034c75c49db/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134323638373233392f736869656c64)](https://styleci.io/repos/142687239)[![Total Downloads](https://camo.githubusercontent.com/def4020db8d29d94a1e65273e4f124b4120baa4744df54af9826c6b65bc27a1d/68747470733a2f2f706f7365722e707567782e6f72672f616964796e6d616b6861746165762f656c6f7175656e742d6a736f6e2d6d6163726f732f646f776e6c6f616473)](https://packagist.org/packages/aidynmakhataev/eloquent-json-macros)[![License](https://camo.githubusercontent.com/d7aeb00ae33a11eb09ffdf445d8c54254b68f525deb27a3b5e72d323e9139eeb/68747470733a2f2f706f7365722e707567782e6f72672f616964796e6d616b6861746165762f656c6f7175656e742d6a736f6e2d6d6163726f732f6c6963656e7365)](https://packagist.org/packages/aidynmakhataev/eloquent-json-macros)

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

[](#installation)

You can install the package using composer

```
$ composer require aidynmakhataev/eloquent-json-macros
```

Features
--------

[](#features)

- Support macros:

    - [`jsonContains`](#jsonContains)
    - [`orJsonContains`](#orJsonContains)
    - [`whereJsonContainsPath`](#whereJsonContainsPath)
    - [`orWhereJsonContainsPath`](#orWhereJsonContainsPath)
    - [`whereJsonDepth`](#whereJsonDepth)
    - [`orWhereJsonDepth`](#orWhereJsonDepth)
    - [`whereJsonExtract`](#whereJsonExtract)
    - [`orWhereJsonExtract`](#orWhereJsonExtract)
    - [`whereJsonLength`](#whereJsonLength)
    - [`orWhereJsonLength`](#orWhereJsonLength)
    - [`selectJsonDepth`](#selectJsonDepth)
    - [`selectJsonLength`](#selectJsonLength)
- Available helpers:

    - json\_array\_append
    - json\_array\_insert
    - json\_insert
    - json\_remove
    - json\_replace
    - json\_set

Usage
-----

[](#usage)

Let's say we have a table `events` with json columns - `browser` and `members`;

###### Browser (dummy json object)

[](#browser-dummy-json-object)

```
{"os": "Windows", "name": "Safari", "resolution": {"x": 1920, "y": 1080}}
```

###### Members (dummy json array)

[](#members-dummy-json-array)

```
[{"id": 6, "info": {"job": "Electrolytic Plating Machine Operator", "email": "prohaska.mervin@example.net", "card_type": "Visa"}, "name": "Prof. Eldridge Legros"}, {"id": 8, "info": {"job": "Urban Planner", "email": "casandra54@example.org", "card_type": "Master Card"}, "name": "Ms. Alayna Ziemann DDS"}]
```

### `jsonContains`

[](#jsoncontains)

Add where 'JSON\_CONTAINS' clause to the query for indicates whether JSON document contains specific object at path

More on: [https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function\_json-contains](https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function_json-contains)

##### Example (for `browser`json object column)

[](#example-for-browserjson-object-column)

```
use App\Models\Event;

Event::jsonContains('browser->os', 'Windows')->get();
Event::jsonContains('browser->resolution.x', 1920)->get();
```

##### Example (for `member`json array column)

[](#example-for-memberjson-array-column)

```
use App\Models\Event;

Event::jsonContains('members->[*].id', 6)->get();
Event::jsonContains('members->[1].info.email', 'casandra54@example.org')->get();
```

### `orJsonContains`

[](#orjsoncontains)

Add an orWhere 'JSON\_CONTAINS' clause to the query for indicates whether JSON document contains specific object at path

Usage will be same as in [`jsonContains`](#jsonContains) macro;

### `whereJsonContainsPath`

[](#wherejsoncontainspath)

Add a where 'JSON\_CONTAINS\_PATH' clause to the query for indicates whether JSON document contains any data at path

More on: [https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function\_json-contains-path](https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function_json-contains-path)

##### Example (for `browser`json object column)

[](#example-for-browserjson-object-column-1)

For single path

```
Event::whereJsonContainsPath('browser', 'resolution')->get();
```

For multiple path

```
Event::whereJsonContainsPath('browser', ['resolution', 'os'])->get();
```

You can also optionally pass a third parameter ('one' or 'all'), by default used 'one'

```
Event::whereJsonContainsPath('browser', ['resolution', 'test'], 'all')->get();
```

##### Example (for `member`json array column)

[](#example-for-memberjson-array-column-1)

```
Event::whereJsonContainsPath('members', '[*].info')->get();
Event::whereJsonContainsPath('members', ['[*].info', '[1].test'])->get();
```

### `orWhereJsonContainsPath`

[](#orwherejsoncontainspath)

Add an orWhere 'JSON\_CONTAINS\_PATH' clause to the query for indicates whether JSON document contains any data at path

Usage will be same as in [`whereJsonContainsPath`](#whereJsonContainsPath) macro;

### `whereJsonDepth`

[](#wherejsondepth)

Add a where 'JSON\_DEPTH' clause to the query for indicates depth of JSON document

More on: [https://dev.mysql.com/doc/refman/5.7/en/json-attribute-functions.html#function\_json-depth](https://dev.mysql.com/doc/refman/5.7/en/json-attribute-functions.html#function_json-depth)

##### Example (for `browser`json object column)

[](#example-for-browserjson-object-column-2)

```
Event::whereJsonDepth('browser->resolution', '>', 1)->get();
Event::whereJsonDepth('browser->os',  2)->get();
Event::whereJsonDepth('browser->resolution.x',  '[*].info.job', '>=', 1)->get();
Event::whereJsonDepth('members->[1].info.phones[0].fax', '>', 0)->get();
```

### `orWhereJsonDepth`

[](#orwherejsondepth)

Add an orWhere 'JSON\_DEPTH' clause to the query for indicates depth of JSON document

Usage will be same as in [`whereJsonDepth`](#whereJsonDepth) macro;

### `whereJsonExtract`

[](#wherejsonextract)

Add a where "JSON\_EXTRACT" clause to the query.

More on: [https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function\_json-extract](https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function_json-extract)

##### Example (for `browser`json object column)

[](#example-for-browserjson-object-column-3)

```
Event::whereJsonExtract('browser->resolution.x', '>', 1500)->get();
Event::whereJsonExtract('browser->name', 'Mozilla Firefox')->get();
```

##### Example (for `member`json array column)

[](#example-for-memberjson-array-column-3)

```
Event::whereJsonExtract('members->[0].id', '>=', 9)->get();
Event::whereJsonExtract('members->[*].info.job', 'LIKE', '%Cleaners%')->get();
```

### `orWhereJsonExtract`

[](#orwherejsonextract)

Add an orWhere "JSON\_EXTRACT" clause to the query.

Usage will be same as in [`whereJsonExtract`](#whereJsonExtract) macro;

### `whereJsonLength`

[](#wherejsonlength)

Add a where 'JSON\_LENGTH' clause to the query.

More on: [https://dev.mysql.com/doc/refman/5.7/en/json-attribute-functions.html#function\_json-length](https://dev.mysql.com/doc/refman/5.7/en/json-attribute-functions.html#function_json-length)

##### Example (for `browser`json object column)

[](#example-for-browserjson-object-column-4)

```
Event::whereJsonLength('browser->resolution', '>', 1)->get();
Event::whereJsonLength('browser->os',  4)->get();
Event::whereJsonLength('browser->resolution.x',  '>=', 1)->get();
```

##### Example (for `member`json array column)

[](#example-for-memberjson-array-column-4)

```
Event::whereJsonLength('members->[*]', '>=', 1)->get();
Event::whereJsonLength('members->[1].info.phones[*].fax', '>', 0)->get();
```

### `orWhereJsonLength`

[](#orwherejsonlength)

Add an orWhere 'JSON\_LENGTH' clause to the query

Usage will be same as in [`whereJsonLength`](#whereJsonLength) macro;

### TODO EXPLANATION FOR OTHER MACROS AND HELPERS

[](#todo-explanation-for-other-macros-and-helpers)

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

[](#contributing)

1. Fork it ()
2. Create your feature branch (`git checkout -b feature/fooBar`)
3. Commit your changes (`git commit -am 'Add some fooBar'`)
4. Push to the branch (`git push origin feature/fooBar`)
5. Create a new Pull Request

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

MIT

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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

Unknown

Total

1

Last Release

2845d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/05bd73f86bccc02a979273fd6b74f2573e3f3c1d2120a879a15c74d8d6abbf63?d=identicon)[AidynMakhataev](/maintainers/AidynMakhataev)

---

Top Contributors

[![AidynMakhataev](https://avatars.githubusercontent.com/u/19181566?v=4)](https://github.com/AidynMakhataev "AidynMakhataev (13 commits)")

---

Tags

eloquent-jsoneloquent-json-macroseloquent-macroslaravellaravel-5-packagelaravel-mysql-jsonmacroslaraveleloquent jsonEloquentJsonMacros

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aidynmakhataev-eloquent-json-macros/health.svg)

```
[![Health](https://phpackages.com/badges/aidynmakhataev-eloquent-json-macros/health.svg)](https://phpackages.com/packages/aidynmakhataev-eloquent-json-macros)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[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)[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)
