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

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

spekt08/laravel-search
======================

A Laravel package for advanced search functionality

03PHP

Since Nov 26Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Search Package
======================

[](#laravel-search-package)

A Laravel package to provide advanced, modular search functionality using customizable search cases.

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

[](#installation)

1. **Install the package** via Composer:

    ```
    composer require spekt08/laravel-search:dev-main
    ```
2. **Publish the configuration file** (if applicable):

    ```
    php artisan vendor:publish --provider="spekt08\Search\SearchServiceProvider" --tag=config
    ```

---

Usage
-----

[](#usage)

### 1. **Initialize the Search Service**

[](#1-initialize-the-search-service)

The `SearchService` requires a model to operate on. You can instantiate it as follows:

```
use spekt08\Search\SearchService;

$service = app(SearchService::class, [
    'model' => \App\Models\User::class
]);
```

---

### 2. **Perform a Search**

[](#2-perform-a-search)

Call the `search` method with the desired query parameters. For example:

```
$queries = [
    'name' => 'John',     // Filter users by name
    'created_at' => '2025-01-01', // Filter by creation date
    'order' => 'asc',     // Sort in ascending order
];

$result = $service->search($queries);
```

This will return a **paginated** result set.

---

### 3. **Use with a Resource**

[](#3-use-with-a-resource)

If you are using Laravel API Resources, you can pass the resource class as the second parameter of the `search` method:

```
use App\Http\Resources\UserResource;

$result = $service->search($queries, UserResource::class);
```

This will transform each result using the provided resource.

---

### 4. **Custom Search Cases**

[](#4-custom-search-cases)

The package includes three default search cases:

- **AttributeCase**: Filters based on model attributes.
- **OrderCase**: Sorts results by a given column (default is `created_at`).
- **CallbackCase**: Allows adding custom callbacks to modify the query.

You can add custom cases by implementing the `SearchCaseInterface`:

```
use spekt08\Search\Cases\SearchCaseInterface;
use Illuminate\Database\Eloquent\Builder;

class CustomCase implements SearchCaseInterface
{
    public function searchQuery(Builder $query, array $params): Builder
    {
        if (isset($params['custom_filter'])) {
            $query->where('custom_column', $params['custom_filter']);
        }
        return $query;
    }
}
```

Add the custom case to the service:

```
$customCase = new CustomCase();
$service->add($customCase);
```

---

### 5. **Configuration Options**

[](#5-configuration-options)

If the package includes a `config/search.php` file, you can customize the default behavior, such as:

- Excluded columns (`not_columns`).
- Default date columns (`date_columns`).

---

Example
-------

[](#example)

```
$service = app(SearchService::class, ['model' => \App\Models\Post::class]);

$queries = [
    'title' => 'Laravel',
    'author' => 'Taylor',
    'order' => 'desc',
    'callbacks' => [
        function ($query) {
            $query->where('status', 'published');
        },
    ],
];

$result = $service->search($queries, \App\Http\Resources\PostResource::class);
```

---

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

[](#contributing)

Feel free to open issues or submit pull requests for new features, bug fixes, or improvements.

---

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance30

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/0c53ce11dc9c5eae8480ad679b35cc4290ad46f525b6e8063197f1a01a1daa3a?d=identicon)[spektr08](/maintainers/spektr08)

---

Top Contributors

[![spektr08](https://avatars.githubusercontent.com/u/6851806?v=4)](https://github.com/spektr08 "spektr08 (7 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/spekt08-laravel-search/health.svg)](https://phpackages.com/packages/spekt08-laravel-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)
