PHPackages                             djl997/laravel-search-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. djl997/laravel-search-query-builder

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

djl997/laravel-search-query-builder
===================================

A `Illuminate\\Database\\Query\\Builder` macro to easily search on multiple database columns.

1.3.2(9mo ago)0465MITPHPPHP ^8.0

Since Apr 13Pushed 9mo ago1 watchersCompare

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

READMEChangelog (4)Dependencies (1)Versions (7)Used By (0)

Laravel Search Query Builder
============================

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/93d6a3c957cc696560f94b04f484f197b1650b362a9fdaa58b965149ca9ff6e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646a6c3939372f6c61726176656c2d7365617263682d71756572792d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/djl997/laravel-search-query-builder)[![Total Downloads](https://camo.githubusercontent.com/697e7212c1c37a2fee1ada535e2a33c99d0c9e616ee702c3531b21737a3367b8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646a6c3939372f6c61726176656c2d7365617263682d71756572792d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/djl997/laravel-search-query-builder)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Laravel Search Query Builder is a `Illuminate\Database\Query\Builder` macro to easily search on multiple database columns and model relationships.

Let's imagine a case where you want to return all users with *something* in their `name` or `bio` field.

```
$search = 'Cesar';

// vanilla laravel
User::where('name', 'LIKE', '%'. $search .'%')->orWhere('bio', 'LIKE', '%'. $search .'%')->get();

// laravel with laravel-search-query-builder package
User::search(['name', 'bio'], $search)->get();
```

This example is not very difficult to achieve in Laravel, but it can grow very quickly, especially if you also want to search in model relationships like posts or comments for example.

Let's see how the Laravel Search Query Builder package can improve this situation.

Requirements
------------

[](#requirements)

Laravel Search Query Builder requires PHP 8+ and Laravel 9+.

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

[](#installation)

You can install the package via composer:

```
composer require djl997/laravel-search-query-builder

```

Usage
-----

[](#usage)

### Basic search term

[](#basic-search-term)

The most basic call to the `search` method requires two arguments:

1. an array of columns,
2. the search value.

For example, the following query retrieves users where the `name` column or the value of the `bio` column is *like* "Cesar".

```
$search = 'Cesar';

User::search(['name', 'bio'], $search)->get();
```

This will generate a query where "Cesar" is LIKE the `name` or LIKE `bio` column. For clarification, the search term is wrapped between `%...%` to check if (a part of) the string is present.

### Multiple search terms

[](#multiple-search-terms)

You can also perform multiple searches at once by separating them with a komma.

```
$search = 'Cesar, Victoria';

User::search(['name', 'bio'], $search)->get();
```

This will generate a query for each part of the search term, exploded on a `,` by default.

#### Change the separator

[](#change-the-separator)

If you want to change the delimiter, you can do so by changing the third argument.

```
User::search(['name', 'bio'], 'Cesar Victoria', '|')->get();
```

This will generate a query for each part of the search term, exploded on a `|`.

### Search multiple relationships

[](#search-multiple-relationships)

As you probably know, the `whereHas` method gives you a lot of power to define additional query constraints. And you guessed it, you can use the `search` method here as well.

For example, the following query will return all users with "Laravel is cool" in their bios + all users who write posts that include this phrase in the title or body.

```
$search = 'Laravel is cool';

User::search(['bio'], $search)
    ->orWhereHas('posts', function($query) use ($search) {
        $query->search(['title', 'body'], $search);
    })
    ->get();
```

### Combine search with other queries

[](#combine-search-with-other-queries)

Since the `search` method is developed to be a macro and extend the `Illuminate\Database\Query\Builder` it can be used inline with any other Builder methods such as `whereIn`, `withTrashed` or `orderBy`, or your very own macros.

```
$search = 'Laravel is cool';

User::whereIn('role', ['author', 'reviewer'])
    ->where(function($query) { //see note below
        ->search(['bio'], $search)
        ->orWhereHas('posts', function($query) use ($search) {
            $query
                ->search(['title', 'body'], $search)
                ->whereNotNull('published_at');
        })
        ->orWhereHas('comments', function($query) use ($search) {
            $query->search(['body'], $search);
        })
    })
    ->withTrashed()
    ->orderBy('name')
    ->get();
```

This will return a ordered list of users with author-, or reviewer roles (deleted AND non-deleted), with "Laravel is cool" in their bios, published posts or comments, ordered by name.

> **Note!** The search query is wrapped in a where query, because you most likely don't want the 'orWheres' to bypass any other filters.

### Dynamic columns search

[](#dynamic-columns-search)

This is a short-sighted example of how you can also make the columns dynamic:

```

```

```
$search = $request->input('search');
$columns = $request->input('userColumns');

User::search($columns, $search)->get();
```

Changelog
---------

[](#changelog)

Please see the GitHub releases for more information on what has changed recently.

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

[](#contributing)

Contributions or ideas are welcome.

License
-------

[](#license)

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

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance58

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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

Every ~170 days

Recently: every ~212 days

Total

6

Last Release

271d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/61d06c885745a581b7313ca440075d14611fa5dc7840e43031d2fd2a056a50e4?d=identicon)[djl997](/maintainers/djl997)

---

Top Contributors

[![djl997](https://avatars.githubusercontent.com/u/27086857?v=4)](https://github.com/djl997 "djl997 (14 commits)")

---

Tags

searchlaraveleloquentbuilder-macrodatabase-search

### Embed Badge

![Health badge](/badges/djl997-laravel-search-query-builder/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17649.9k](/packages/lacodix-laravel-model-filter)[mozex/laravel-scout-bulk-actions

A Laravel Scout extension for bulk importing and flushing of all models.

1033.4k](/packages/mozex-laravel-scout-bulk-actions)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

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