Dynamic JSON filtering for Eloquent Builder with Laravel 9-12 & PHP 8.1-8.4 support (MySQL, PostgreSQL & SQLite).
pawsmedz/laravel-json-filter is a Laravel package for dynamic json filtering for eloquent builder with laravel 9-12 & php 8.1-8.4 support (mysql, postgresql & sqlite)..
It currently has 0 GitHub stars and 3 downloads on Packagist (latest version v1.3.1).
Install it with composer require pawsmedz/laravel-json-filter.
Discover more Laravel packages by pawsmedz
or browse all Laravel packages to compare alternatives.
Last updated
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.
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.
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();
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();
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();
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();
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();
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();
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();
The package automatically detects your database driver and uses the appropriate JSON syntax:
-- 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
-- jsonFilter('meta->status', '=', 'active')
WHERE meta->>'status' = 'active'
-- jsonSelect('meta->status as user_status')
SELECT meta->>'status' as user_status
Falls back to basic column operations for compatibility.
Run the test suite:
composer test
Run tests with coverage:
composer test:coverage
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.