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(1y ago)001MITPHP

Since Jun 18Pushed 1y 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 today

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

21

—

LowBetter than 18% of packages

Maintenance48

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

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

381d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/107402522?v=4)[NYCU CSIT](/maintainers/nycu-csit)[@nycu-csit](https://github.com/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

[typicms/base

A modular multilingual CMS built with Laravel, enabling developers to manage structured content like pages, news, events, and more.

1.6k20.4k](/packages/typicms-base)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[crumbls/layup

A visual page builder plugin for Filament 5 — Divi-style grid layouts with extensible widgets.

592.7k2](/packages/crumbls-layup)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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