PHPackages                             nycu-csit/spatie-laravel-query-builder-extension - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. nycu-csit/spatie-laravel-query-builder-extension

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nycu-csit/spatie-laravel-query-builder-extension
================================================

NYCU CSIT custom filters for spatie/laravel-query-builder

v0.0.1(10mo ago)001MITPHP

Since Jun 18Pushed 10mo agoCompare

[ Source](https://github.com/nycu-csit/laravel-query-builder-extension)[ Packagist](https://packagist.org/packages/nycu-csit/spatie-laravel-query-builder-extension)[ RSS](/packages/nycu-csit-spatie-laravel-query-builder-extension/feed)WikiDiscussions main Synced 1mo ago

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

Spatie Laravel Query Builder Extension
======================================

[](#spatie-laravel-query-builder-extension)

This package currently maintains the custom filters required by NYCU CSIT for Spatie/laravel-query-builder.

`Spatie\QueryBuilder\QueryBuilder` basic usage:

```
$users = QueryBuilder::for(User::class)
    // this allow a filter on the `name` column
    ->allowedFilters('name')
    ->get();

// GET /users?filter[name]=John
// $users will contain only users with the name "John"
```

For more details, please refer to the [Spatie/laravel-query-builder documentation](https://spatie.be/docs/laravel-query-builder/v6/introduction).

Spatie\\QueryBuilder integration with NycuCsit\\LaravelRestfulUtils
-------------------------------------------------------------------

[](#spatiequerybuilder-integration-with-nycucsitlaravelrestfulutils)

`Spatie\QueryBuilder\QueryBuilder` may be used in the `buildIndexQuery` method of a controller that use `NycuCsit\LaravelRestfulUtils\Controller\HasResourceActions` trait.

```
use NycuCsit\SpatieLaravelQueryBuilderExtension\CustomFilters\FiltersIn;

class ProductController extends Controllor
{
    use HasResourceActions;
    //...
    public function buildIndexQuery(): object
    {
        $query = QueryBuilder::for($this->query)
            ->allowedFilters([
                AllowedFilter::custom('category.name', new FiltersIn()),
                AllowedFilter::exact('name'),
            ])
            ->allowedSorts([
                'created_at',
                'updated_at',
            ])
            ->allowedIncludes([
                'creator',
            ])
            ->defaultSort('-created_at');

        return $query;
    }
    //...
}
```

Development
-----------

[](#development)

The tests use sqlite in memory database, so you may need to install the sqlite driver for your PHP installation.

```
sudo apt install php-sqlite3
```

In some cases, two filters may interfere each others, do some tests if there are filters very likely to be used at the same time. [One example](https://laracasts.com/discuss/channels/eloquent/how-to-use-multiple-filters-in-spatie-query-builder)

Custom Filters
--------------

[](#custom-filters)

The filters is usually used under `allowedFilters` method of `Spatie\QueryBuilder\QueryBuilder`.

You can use the custom filters by the way provided by [Spatie/laravel-query-builder docs](https://spatie.be/docs/laravel-query-builder/v6/features/filtering#content-custom-filters)

### FiltersIn, FiltersNotIn

[](#filtersin-filtersnotin)

- Works on Relation models
- Can works on a column at the same time

```
$products = QueryBuilder::for(Product::class)
    ->allowedFilters([
        AllowedFilter::custom('category.name', new FiltersIn()),
    ])
    ->get();

// GET /products?filter[category]=∈electronics,books
// $products will contain only products that belong to the categories named "electronics" or "books"
```

```
$products = QueryBuilder::for(Product::class)
    ->allowedFilters([
        AllowedFilter::custom('category.name', new FiltersNotIn()),
    ])
    ->get();

// GET /products?filter[category]=∉electronics,books
// $products will contain only products that do not belong to the categories named "electronics" or "books"
```

`FiltersIn` and `FiltersNotIn` can be used on a column of at the same time.

```
$products = QueryBuilder::for(Product::class)
    ->allowedFilters([
        AllowedFilter::custom('category.name', new FiltersIn()),
        AllowedFilter::custom('category.name', new FiltersNotIn()),
    ])
    ->get();
// GET /products?filter[category]=∈electronics,books
// $products will contain only products that belong to the categories named "electronics" or "books"
// GET /products?filter[category]=∉electronics,books
// $products will contain only products that do not belong to the categories named "electronics" or "books"
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance53

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 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

329d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6b52c3484e8cbef7ae4cd3112390f3c3c860046219663c531f42ae2990ac3f1f?d=identicon)[nycu-csit](/maintainers/nycu-csit)

---

Top Contributors

[![ppodds](https://avatars.githubusercontent.com/u/11408727?v=4)](https://github.com/ppodds "ppodds (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nycu-csit-spatie-laravel-query-builder-extension/health.svg)

```
[![Health](https://phpackages.com/badges/nycu-csit-spatie-laravel-query-builder-extension/health.svg)](https://phpackages.com/packages/nycu-csit-spatie-laravel-query-builder-extension)
```

###  Alternatives

[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)

PHPackages © 2026

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