PHPackages                             theokbokki/laravel-filter-search - 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. theokbokki/laravel-filter-search

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

theokbokki/laravel-filter-search
================================

A powerful syntax for filtering models through a search box (Similar to Github projects)

04PHP

Since Dec 31Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel filter search
=====================

[](#laravel-filter-search)

Warning

This package wasn't yet tested in production use at your own risks. Tests should arrive soon.

Why?
----

[](#why)

I was making a website that needed a lot of filtering flexibility and a simple search wouldn't do. I could have made a bunch of filters with selects, checkboxes etc, but that would quickliy have become messy.

Then I remembered how github projects does it and it solved all the problems at once!

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

[](#requirements)

- PHP 8.0+
- Laravel 9.0+

Installing
----------

[](#installing)

You can install the package via composer

```
composer require theokbokki/laravel-filter-search
```

Using
-----

[](#using)

The model you want to make searchable should have the trait `HasFilterSearch` and it should implement these 2 methods:

```
public static function defaultSearchFields(): array
{
    return [
        // the list of the model fields you want to be able to seach normally.
    ];
}

public static function allowedSearchFields(): array
{
    return [
        // the list of the model fields you want to allow filtering on.
    ];
}
```

Then when you want to search (for example in a controller), you use the `handleFilterSearch` method

```
$query = Snippet::handleFilterSearch($searchTerm);
```

The syntax
----------

[](#the-syntax)

The syntax was heavily inspired by the one from Github projects, here's a rundown of the possibilities. One thing to note is that case isn't taken into account, so "TEST" and "test" are the same.

### Regular search

[](#regular-search)

You can simply put a search term like normal and get what you want

Search termsResulttestWill return the records containg the string "test" in the fields specified in `defaultSearchFields()`Field search
------------

[](#field-search)

You can use all the fields speicifed in `allowedSearchFields()` to make the search more precise

Search termsResulttitle:TestWill return the records containg the string "test" in the title fieldCombining filters
-----------------

[](#combining-filters)

You can freely mix and match search terms and filters to get very precise results

Search termsResulttitle:Foo published:true BarWill return the records containg the string "Foo" in the title field, with published = true and Bar in the fields specified in `defaultSearchFields()`Reversing the search
--------------------

[](#reversing-the-search)

You can also add an hyphen before the field or keyword to reverse the search

Search termsResult-title:TestWill return any record not containg the string "test" in the title field-testWill return any record not containg the string "test" in the fields specified in `defaultSearchFields()`What if my search contains space, commas or colons?
---------------------------------------------------

[](#what-if-my-search-contains-space-commas-or-colons)

You can add double quotes around your search to handle space, commas and colons.

Search termsResulttitle:"Sentence: with spaces, colons and commas"Will return any record containg the string "Sentence: with spaces, colons and commas" in the title field

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity16

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c3e9c9ea4afd7d211e01f3e6da7dda4d5f4570e6871629b506bfc1a2f7f2d507?d=identicon)[theokbokki](/maintainers/theokbokki)

---

Top Contributors

[![theokbokki](https://avatars.githubusercontent.com/u/90846584?v=4)](https://github.com/theokbokki "theokbokki (5 commits)")

### Embed Badge

![Health badge](/badges/theokbokki-laravel-filter-search/health.svg)

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

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)[handcraftedinthealps/zendsearch

a general purpose text search engine written entirely in PHP 5

39921.0k35](/packages/handcraftedinthealps-zendsearch)

PHPackages © 2026

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