PHPackages                             pawsmedz/laravel-json-filter - 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. pawsmedz/laravel-json-filter

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

pawsmedz/laravel-json-filter
============================

Dynamic JSON filtering for Eloquent Builder with Laravel 9-12 &amp; PHP 8.1-8.4 support (MySQL, PostgreSQL &amp; SQLite).

v1.3.1(6mo ago)13MITPHPPHP ^8.1|^8.2|^8.3|^8.4CI passing

Since Nov 1Pushed 6mo agoCompare

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

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

Laravel JSON Filter
===================

[](#laravel-json-filter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d9369a11d81c148e456a02ac2aaad34bfa51b73abab3ba01357ed1b89718f340/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706177736d65647a2f6c61726176656c2d6a736f6e2d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pawsmedz/laravel-json-filter)[![GitHub Tests Action Status](https://camo.githubusercontent.com/058329cde6c7b4f52235ba7fb3a76cb648c251e173baaf95fcc142d1726752f5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f70617773313233342f6c61726176656c2d6a736f6e2d66696c7465722f74657374733f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/paws1234/laravel-json-filter/actions?query=workflow%3Atests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/b43ded8f45b114ec2f392f1476d6e0f014ec9842fcba0fe2a5fe6fc7a41d33dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706177736d65647a2f6c61726176656c2d6a736f6e2d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pawsmedz/laravel-json-filter)

A Laravel package that provides fluent, database-agnostic JSON querying macros for Eloquent and Query Builder. Seamlessly work with JSON columns across MySQL, PostgreSQL, and SQLite with a consistent, expressive API.

Features
--------

[](#features)

- 🔍 **Database Agnostic**: Works seamlessly with MySQL, PostgreSQL, and SQLite
- 🎯 **Fluent API**: Clean, expressive syntax for JSON queries
- 🚀 **Multiple Macros**: Filter, select, order, search, and check existence
- 🔧 **Easy Integration**: Auto-discovery service provider
- 🧪 **Well Tested**: Comprehensive test suite
- 📦 **Laravel Compatible**: Supports Laravel 9.x, 10.x, 11.x, and 12.x

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

[](#installation)

You can install the package via Composer:

```
composer require pawsmedz/laravel-json-filter
```

The package will automatically register its service provider via Laravel's auto-discovery feature.

Usage
-----

[](#usage)

### Basic JSON Filtering

[](#basic-json-filtering)

Filter records based on JSON field values:

```
use App\Models\User;

// Filter by JSON field value
$activeUsers = User::query()
    ->jsonFilter('meta->status', '=', 'active')
    ->get();

// Filter nested JSON paths
$proUsers = User::query()
    ->jsonFilter('meta->subscription->plan', '=', 'pro')
    ->get();
```

### JSON Where In

[](#json-where-in)

Filter records where JSON field matches any value in an array:

```
// Find users with specific statuses
$users = User::query()
    ->jsonWhereIn('meta->status', ['active', 'pending'])
    ->get();

// Multiple subscription plans
$subscribers = User::query()
    ->jsonWhereIn('meta->subscription->plan', ['pro', 'enterprise'])
    ->get();
```

### JSON Contains (Search)

[](#json-contains-search)

Search for records where JSON field contains a specific substring:

```
// Search in JSON arrays or strings
$developers = User::query()
    ->jsonContains('meta->skills', 'php')
    ->get();

// Search in nested fields
$users = User::query()
    ->jsonContains('meta->profile->bio', 'developer')
    ->get();
```

### JSON Exists

[](#json-exists)

Check if a JSON path exists in records:

```
// Find users with subscription data
$subscribers = User::query()
    ->jsonExists('meta->subscription->plan')
    ->get();

// Check for nested paths
$profileUsers = User::query()
    ->jsonExists('meta->profile->preferences')
    ->get();
```

### JSON Select

[](#json-select)

Select specific JSON fields as columns:

```
// Select JSON field with auto-generated alias
$users = User::query()
    ->jsonSelect('meta->status')
    ->get();

// Select with custom alias
$users = User::query()
    ->jsonSelect('meta->profile->country as user_country')
    ->get();

// Multiple JSON selections
$users = User::query()
    ->jsonSelect('meta->status')
    ->jsonSelect('meta->subscription->plan as plan')
    ->jsonSelect('meta->profile->country as country')
    ->get();
```

### JSON Order By

[](#json-order-by)

Order results by JSON field values:

```
// Order by JSON field (ascending)
$users = User::query()
    ->jsonOrderBy('meta->score')
    ->get();

// Order by JSON field (descending)
$topUsers = User::query()
    ->jsonOrderBy('meta->score', 'desc')
    ->get();

// Complex ordering
$users = User::query()
    ->jsonOrderBy('meta->subscription->plan', 'desc')
    ->jsonOrderBy('meta->score', 'desc')
    ->get();
```

### Combining Multiple Macros

[](#combining-multiple-macros)

Chain multiple JSON operations for complex queries:

```
$results = User::query()
    ->jsonFilter('meta->status', '=', 'active')
    ->jsonExists('meta->subscription')
    ->jsonWhereIn('meta->subscription->plan', ['pro', 'enterprise'])
    ->jsonContains('meta->skills', 'laravel')
    ->jsonSelect('meta->profile->name as display_name')
    ->jsonSelect('meta->subscription->plan as plan')
    ->jsonOrderBy('meta->score', 'desc')
    ->get();
```

Database Support
----------------

[](#database-support)

The package automatically detects your database driver and uses the appropriate JSON syntax:

### MySQL

[](#mysql)

```
-- jsonFilter('meta->status', '=', 'active')
WHERE JSON_UNQUOTE(JSON_EXTRACT(meta, '$.status')) = 'active'

-- jsonSelect('meta->status as user_status')
SELECT JSON_UNQUOTE(JSON_EXTRACT(meta, '$.status')) as user_status
```

### PostgreSQL

[](#postgresql)

```
-- jsonFilter('meta->status', '=', 'active')
WHERE meta->>'status' = 'active'

-- jsonSelect('meta->status as user_status')
SELECT meta->>'status' as user_status
```

### SQLite

[](#sqlite)

Falls back to basic column operations for compatibility.

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 9.x, 10.x, 11.x, or 12.x
- MySQL, PostgreSQL, or SQLite database

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Run tests with coverage:

```
composer test:coverage
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review our security policy on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Rayvand Jasper Valle Medrano](https://github.com/paws1234)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance67

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

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

Total

5

Last Release

193d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.3.1PHP ^8.1|^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/671917e9a40da09a14d638e5e2c9a8a7997b877f665939d0d0bc6bfa65370196?d=identicon)[paws1234](/maintainers/paws1234)

---

Top Contributors

[![paws1234](https://avatars.githubusercontent.com/u/131801287?v=4)](https://github.com/paws1234 "paws1234 (17 commits)")

---

Tags

jsonlaravellaravel 12mysqlsqlitepostgresqleloquentqueryfilter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pawsmedz-laravel-json-filter/health.svg)

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

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k25.2M34](/packages/kirschbaum-development-eloquent-power-joins)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[jerome/filterable

Streamline dynamic Eloquent query filtering with seamless API request integration and advanced caching strategies.

19226.1k](/packages/jerome-filterable)[aldemeery/sieve

A simple, clean and elegant way to filter Eloquent models.

1396.3k](/packages/aldemeery-sieve)

PHPackages © 2026

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