New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

djl997/laravel-search-query-builder

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

Larablocks Analysis

djl997/laravel-search-query-builder works with Laravel 12 and 13 (latest release 2.0.0, Nov 18, 2026).

Laravel 9, 10 and 11 in earlier releases.

Promising: maintained and up to date, meets 2 of 4 checks; not yet widely used.

  • Works with Laravel 13, the current version
  • Released in the last 12 months (Nov 18, 2026)
  • 26 downloads a month (needs 10,000)
  • 0 GitHub stars (needs 100)

State

Actively maintained
  • Last stable release: Nov 18, 2026.
  • 3 releases in the last 12 months.
  • First released: Apr 13, 2023.
  • Monthly downloads: 26, up 160% from six months ago.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 2, 2026.

Install
composer require djl997/laravel-search-query-builder
Latest Version:2.0.0
PHP:^8.2
Laravel:12 · 13
Older releases:9 · 10 · 11
License:MIT
Last Updated:Nov 18, 2026
Links: GitHub  ·  Packagist
Maintainer: djl997

Laravel Search Query Builder

Latest Version on Packagist Total Downloads Software 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

Laravel Search Query Builder requires PHP 8.2+ and Laravel 12+.

Installation

You can install the package via composer:

composer require djl997/laravel-search-query-builder

Usage

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

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

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

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

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) use ($search) { //see note below
        $query
            ->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.

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

<input type="text" name="search" value="Laravel is cool"/>
<input type="checkbox" name="userColumns[]" value="name"/>
<input type="checkbox" name="userColumns[]" value="bio"/>
$search = $request->input('search');
$columns = array_intersect((array) $request->input('userColumns'), ['name', 'bio']);

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

Note! Always whitelist user-supplied column names, so users can't search on columns like password.

Changelog

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

Contributing

Contributions or ideas are welcome.

License

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

Related Packages

iverberk/larasearch

Elasticsearch enabled Eloquent models

15,577 222
craftcodery/laravel-searchable

Searchable trait for Laravel Eloquent models

8,523 0
laravellegends/eloquent-filter

A simple Eloquent filter to make easy API filtering

23,078 39
archy-bold/eloquent-searchable

A service layer to provide support for search on your Eloquent models. WIP only...

2,002 7
websecret/laravel-search

Laravel Eloquent models with Elasticsearch 2

342 4

Version History

Version Released PHP Laravel License
2.0.0 ^8.2 ^12.0|^13.0 MIT
1.4.0 ^8.0 ^9.0|^10.0|^11.0|^12.0|^13.0 MIT
1.3.4 ^8.0 ^9.0|^10.0|^11.0|^12.0|^13.0 MIT
1.3.2 ^8.0 ^9.0|^10.0|^11.0|^12.0 MIT
1.3.1 ^8.0 ^9.0|^10.0|^11.0|^12.0 MIT