PHPackages                             red-fern/laravel-array-query-builder - 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. red-fern/laravel-array-query-builder

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

red-fern/laravel-array-query-builder
====================================

Query an eloquent model using arrays

0.3.0(5y ago)016MITPHPPHP ^7.1CI failing

Since Dec 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Red-Fern/laravel-array-query-builder)[ Packagist](https://packagist.org/packages/red-fern/laravel-array-query-builder)[ RSS](/packages/red-fern-laravel-array-query-builder/feed)WikiDiscussions master Synced today

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

Laravel Array Query Builder
===========================

[](#laravel-array-query-builder)

[![](https://github.com/Red-Fern/laravel-array-query-builder/workflows/Run%20PHP%20Tests/badge.svg)](https://github.com/Red-Fern/laravel-array-query-builder/workflows/Run%20PHP%20Tests/badge.svg)[![StyleCI](https://camo.githubusercontent.com/3ca73475670306aedc5318a017087c83d72e183727b803a965250109c84b5c5c/68747470733a2f2f7374796c6563692e696f2f7265706f732f3232353732373936332f736869656c64)](https://styleci.io/repos/225727963)

This package allows you to add where clauses to eloquent query builders using multidimensional arrays. By following a simple structure, you can chain multiple query conditions, nested conditions and relational queries.

```
$queryArray = [
    'condition' => 'or',
    'rules' => [
        [
            'field' => 'name',
            'operator' => '=',
            'value' => 'john'
        ],
        [
            'field' => 'age',
            'operator' => '>',
            'value' => 25
        ],
    ]
];

$users = User::arrayWheres($queryArray)->get();

```

The **condition** describes how the coinciding rules are applied. In this case the **name** and **age** fields will be wrapped in an **OR** query.

The above section would generate the following eloquent query builder:

```
$users = User::where('name', 'john')
            ->orWhere('age', '>', 25)
            ->get();

```

Operator Types
--------------

[](#operator-types)

When querying against fields, there are several options for the operator. These options are:

### Comparison Operators

[](#comparison-operators)

The standard comparison operators e.g. =, &lt;, &gt;, &lt;=, &gt;=. An example below:

```
$rules = [
    'field' => 'age',
    'operator' => '>=',
    'value' => 25
];

```

This becomes:

```
$query->where('age','>=',25);

```

### Nullable checks

[](#nullable-checks)

Checking for if a column is **"null"** or **"not null"** e.g.

```
$rules = [
    'field' => 'dob',
    'operator' => 'null'
];

```

This becomes:

```
$query->whereNull('dob');

```

### Between

[](#between)

Checking if a field value is between array of values:

```
$rules = [
    'field' => 'age',
    'operator' => 'between',
    'value' => [20, 50]
];

```

This becomes:

```
$query->whereBetween('age', [20, 50]);

```

### In/Not in list of values

[](#innot-in-list-of-values)

Checking if field value is **"in"** or **"not in"** an array of values:

```
$rules = [
    'field' => 'id',
    'operator' => 'in',
    'value' => [2, 5, 6]
];

```

This becomes:

```
$query->whereIn('id', [2, 5, 6]);

```

### String comparison

[](#string-comparison)

Checking if a field value contains a string. This is basically an alias for a like query with wildcards e.g.

```
$rules = [
    'field' => 'name',
    'operator' => 'contains',
    'value' => 'john'
];

```

This becomes:

```
$query->where('name', 'like', '%john%');

```

Relations
---------

[](#relations)

You can also query eloquent relations using dot notation.

```
 $queryArray = [
    'condition' => 'and',
    'rules' => [
        [
            'field' => 'name',
            'operator' => 'like',
            'value' => '%john%'
        ],
        [
            'field' => 'orders.order_date',
            'operator' => '>',
            'value' => '2019-01-01 00:00:00'
        ]
    ]
];

$users = User::arrayWheres($queryArray)->get();

```

Using dot notation in the fields, will determine that it will query, in this case the **orders** relation. The above query would become:

```
$users = User::where('name', 'like', '%john%')
        ->whereHas('orders', function($q) {
            $q->where('order_date', '>', '2019-01-01 00:00:00');
        })->get();

```

Nested Queries
--------------

[](#nested-queries)

You can also add nested conditions to build more complex queries such as:

```
$rules = [
    'condition' => 'and',
    'rules' => [
        [
            'condition' => 'or',
            'rules' => [
                [
                    'field' => 'name',
                    'operator' => '=',
                    'value' => 'john'
                ],
                [
                    'field' => 'name',
                    'operator' => '=',
                    'value' => 'james'
                ],
            ]
        ],
        [
            'field' => 'orders.order_date',
            'operator' => '>',
            'value' => '2010-01-01 00:00:00'
        ],
    ]
];

$users = User::arrayWheres($queryArray)->get();

```

The above example shows how you can add nested conditional rules to the array. This follows the same format and you can nested to any depth. The above example would become:

```
$users = User::where(function($q) {
                $q->where('name', '=', 'john')
                    ->orWhere('name', '=', 'james');
            })
            ->whereHas('orders', function($q) {
                $q->where('order_date', '>', '2010-01-01 00:00:00');
            })->get();

```

Future Development
------------------

[](#future-development)

The plan is to expand the capabilities of this package, extending the array capability to also allow query selects, joins, order by, group bys etc.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% 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 ~110 days

Total

4

Last Release

2012d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/aa219403d112f81d85f0baf8d09d134fc1601deac9598a77f3a3cc5eee517c5c?d=identicon)[RedFernWilson](/maintainers/RedFernWilson)

---

Top Contributors

[![RedFernWilson](https://avatars.githubusercontent.com/u/26387822?v=4)](https://github.com/RedFernWilson "RedFernWilson (24 commits)")[![RedFernLiam](https://avatars.githubusercontent.com/u/56090859?v=4)](https://github.com/RedFernLiam "RedFernLiam (3 commits)")

---

Tags

eloquentlaravelquery-builder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/red-fern-laravel-array-query-builder/health.svg)

```
[![Health](https://phpackages.com/badges/red-fern-laravel-array-query-builder/health.svg)](https://phpackages.com/packages/red-fern-laravel-array-query-builder)
```

###  Alternatives

[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)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

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

PHPackages © 2026

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