PHPackages                             foxws/laravel-scout-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. [Search &amp; Filtering](/categories/search)
4. /
5. foxws/laravel-scout-builder

ActiveLibrary[Search &amp; Filtering](/categories/search)

foxws/laravel-scout-builder
===========================

Easily build Scout queries from API requests

0.0.4(2mo ago)21.2k↓44.7%1MITPHPPHP ^8.4CI passing

Since Apr 8Pushed 1mo agoCompare

[ Source](https://github.com/foxws/laravel-scout-builder)[ Packagist](https://packagist.org/packages/foxws/laravel-scout-builder)[ Docs](https://github.com/foxws/laravel-scout-builder)[ GitHub Sponsors](https://github.com/Foxws)[ RSS](/packages/foxws-laravel-scout-builder/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (4)Dependencies (13)Versions (5)Used By (0)

laravel-scout-builder
=====================

[](#laravel-scout-builder)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cae09c32a6f74ede8228bb43620be9fbf2895a7b8f2f11205af94f90bd4770d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f7877732f6c61726176656c2d73636f75742d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/foxws/laravel-scout-builder)[![GitHub Tests Action Status](https://camo.githubusercontent.com/6b25b7a407649739a9ce33de6c3bdd05bca41ead336317ffea27e1a400ee245c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f666f7877732f6c61726176656c2d73636f75742d6275696c6465722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/foxws/laravel-scout-builder/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/42f7ae4b9bb5c53e5f43a69f9d04cb44f264e0fe75406663ff2ffd7775546006/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f666f7877732f6c61726176656c2d73636f75742d6275696c6465722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/foxws/laravel-scout-builder/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/e47ffecd4bd0a554398fe5f9369f9e4e5446107eb4af6c71a2253541bcb4630c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666f7877732f6c61726176656c2d73636f75742d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/foxws/laravel-scout-builder)

A [Laravel Scout](https://laravel.com/docs/scout) query builder inspired by and largely derived from [spatie/laravel-query-builder](https://github.com/spatie/laravel-query-builder). It brings the same `AllowedFilter` / `AllowedSort` API to Scout's search builder, letting you expose safe, declarative search endpoints driven by HTTP query parameters.

> **Credits** — This package is a close adaptation of spatie/laravel-query-builder. All credit for the original architecture, patterns, and API design belongs to [Spatie](https://spatie.be). If this package is useful to you, please consider [supporting Spatie](https://spatie.be/open-source/support-us).

Documentation
-------------

[](#documentation)

- [Filters](docs/filters.md)
- [Sorts](docs/sorts.md)
- [Includes](docs/includes.md)
- [Pagination](docs/pagination.md)
- [Engine Awareness](docs/engine-awareness.md)
- [Configuration](docs/configuration.md)

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

[](#installation)

```
composer require foxws/laravel-scout-builder
```

Publish the config file (optional):

```
php artisan vendor:publish --tag="scout-builder-config"
```

Quick Start
-----------

[](#quick-start)

Add the `Searchable` trait to your model as usual, then build a search endpoint:

```
use Foxws\ScoutBuilder\AllowedFilter;
use Foxws\ScoutBuilder\AllowedSort;
use Foxws\ScoutBuilder\ScoutBuilder;

$results = ScoutBuilder::for(Post::class, $request)
    ->allowedFilters(
        AllowedFilter::exact('status'),
        AllowedFilter::in('tags'),
        AllowedFilter::dynamicOperator('price'),
    )
    ->allowedSorts(
        AllowedSort::latest('recent', 'published_at'),
        AllowedSort::field('title'),
    )
    ->defaultSort('-recent')
    ->get();
```

This reads directly from the incoming `$request`:

ParameterExampleSearch query`?query=laravel`Exact filter`?filter[status]=published`Multi-value filter`?filter[tags]=php,laravel`Operator filter`?filter[price]=gte:100`Sort`?sort=-recent,title`Paginate`?page[number]=2&page[size]=15`Pagination
----------

[](#pagination)

Use `jsonPaginate()` instead of `get()` to return a paginated result following the JSON:API `page[number]` / `page[size]` convention:

```
$results = ScoutBuilder::for(Post::class, $request)
    ->allowedFilters(AllowedFilter::exact('status'))
    ->allowedSorts(AllowedSort::field('title'))
    ->jsonPaginate();
```

ParameterExampleDefaultPage number`?page[number]=2``1`Page size`?page[size]=15``30`The max page size is capped at `30` by default. Both defaults are configurable — see [Pagination](docs/pagination.md).

Wrapping an Existing Scout Builder
----------------------------------

[](#wrapping-an-existing-scout-builder)

```
$builder = Post::search('laravel')->where('is_published', true);

$results = ScoutBuilder::for($builder, $request)
    ->allowedFilters(AllowedFilter::exact('status'))
    ->get();
```

Facade
------

[](#facade)

```
use Foxws\ScoutBuilder\Facades\ScoutBuilder;

$results = ScoutBuilder::for(Post::class, $request)
    ->allowedFilters(AllowedFilter::scope('published'))
    ->get();
```

Differences from spatie/laravel-query-builder
---------------------------------------------

[](#differences-from-spatielaravel-query-builder)

Featurespatie/laravel-query-builderfoxws/laravel-scout-builderUnderlying builderEloquent `Builder`Scout `Builder``AllowedInclude`✅✅ via Scout `query()` callback (database/collection drivers)`FiltersPartial`, `FiltersBeginsWith`, etc.✅— (text search handled by Scout itself)`AllowedFilter::operator()`via `FiltersOperator`✅ first-class with `FilterOperator` enum`AllowedFilter::dynamicOperator()`—✅ colon-token + array payload`AllowedFilter::notIn()`—✅`AllowedSort::latest()` / `oldest()`—✅`jsonPaginate()`✅ (Eloquent only)✅ JSON:API `page[number]`/`page[size]`Engine awareness—✅ `ScoutDriver` + `EngineFeature` enumsRequest scalar castingraw strings✅ auto-casts `'true'`, `'42'`, `'null'`, etc.Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

AI Assistance
-------------

[](#ai-assistance)

This package is developed with AI assistance, primarily using [GitHub Copilot](https://github.com/features/copilot) and [Claude Sonnet](https://www.anthropic.com/claude).

AI tools are used for suggestions and development acceleration. All final implementation decisions, code review, and adjustments are made by the maintainers. AI-generated contributions are welcome in pull requests, provided that a person is actively involved in the implementation and review process.

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

[](#contributing)

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

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

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Spatie](https://spatie.be) and [all spatie/laravel-query-builder contributors](https://github.com/spatie/laravel-query-builder/graphs/contributors) — this package is built on their work
- [francoism90](https://github.com/foxws)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance89

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity44

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

Total

4

Last Release

61d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5028905?v=4)[François M.](/maintainers/francoism90)[@francoism90](https://github.com/francoism90)

---

Top Contributors

[![francoism90](https://avatars.githubusercontent.com/u/5028905?v=4)](https://github.com/francoism90 "francoism90 (16 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

algoliafoxwslaravellaravel-packagelaravel-scoutmeilisearchquery-builderscoutsearchtypesenselaravelfoxwslaravel-scout-builder

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/foxws-laravel-scout-builder/health.svg)

```
[![Health](https://phpackages.com/badges/foxws-laravel-scout-builder/health.svg)](https://phpackages.com/packages/foxws-laravel-scout-builder)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.3M41](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k9.9M87](/packages/dedoc-scramble)[spatie/laravel-health

Monitor the health of a Laravel application

87311.3M149](/packages/spatie-laravel-health)[spatie/laravel-passkeys

Use passkeys in your Laravel app

463755.5k32](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3913.7k](/packages/rawilk-profile-filament-plugin)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24655.3k](/packages/vormkracht10-laravel-mails)

PHPackages © 2026

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