PHPackages                             mr-luke/searcher - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. mr-luke/searcher

AbandonedArchivedLibrary[HTTP &amp; Networking](/categories/http)

mr-luke/searcher
================

Laravel 5 package for REST Url-based quering, filtering &amp; sorting Eloquent models.

v1.0.0(7y ago)017MITPHPPHP &gt;=7.1.3

Since Oct 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/mr-luke/searcher)[ Packagist](https://packagist.org/packages/mr-luke/searcher)[ RSS](/packages/mr-luke-searcher/feed)WikiDiscussions master Synced 1mo ago

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

Searcher - Laravel Eloquent query Package.
==========================================

[](#searcher---laravel-eloquent-query-package)

[![Latest Stable Version](https://camo.githubusercontent.com/70f2aadf490240e83f6241ec132c1a0ce8ba1bdb40c532f85760ceea5b32b304/68747470733a2f2f706f7365722e707567782e6f72672f6d722d6c756b652f73656172636865722f762f737461626c65)](https://packagist.org/packages/mr-luke/searcher)[![Total Downloads](https://camo.githubusercontent.com/d6eab12ba4663c487404ba24fcb85acab7a8d3e9875fae91659fdb8e8ed4cbbe/68747470733a2f2f706f7365722e707567782e6f72672f6d722d6c756b652f73656172636865722f646f776e6c6f616473)](https://packagist.org/packages/mr-luke/searcher)[![License](https://camo.githubusercontent.com/404db80d2174ab69bf0c3363e7b0b3ab4bb68154a3da9dac1d8941e37fdb76a0/68747470733a2f2f706f7365722e707567782e6f72672f6d722d6c756b652f73656172636865722f6c6963656e7365)](https://packagist.org/packages/mr-luke/searcher)

This package is responsible for converting OData(-like) URL Query into SQL query on top of the Eloquent Builder.

- [Getting Started](#getting-started)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Plans](#plans)

Getting Started
---------------

[](#getting-started)

Searcher has been developed using Laravel 5.5. It's recommended to test it out before using with previous versions. PHP &gt;= 7.1.3 is required.

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

[](#installation)

To install through composer, simply put the following in your composer.json file and run `composer update`

```
{
    "require": {
        "mr-luke/searcher": "~1.0"
    }
}
```

Or use the following command

```
composer require "mr-luke/searcher"
```

Next, add the service provider to `app/config/app.php`

```
Mrluke\Searcher\SearcherServiceProvider::class,

```

Configuration
-------------

[](#configuration)

You can see the options for further customization in the [config file](config/searcher.php).

You can also publish config file

```
php artisan vendor:publish
```

Usage
-----

[](#usage)

#### Step 1: Model

[](#step-1-model)

To use `Searcher` you need to setup your `Searchable` Eloquent model before. Add following interface to the model `Mrluke\Searcher\Contracts\Searchable` and create method:

```
/**
 * Determines rules for Searcher.
 *
 * @return array
 */
public static function getSearchableConfig() : array
{
	return [
    	'filter' => ['first' => 'firstName'],
        'query' => ['first', 'last'],
        'sort => ['age' => 'age'],
    ];
}
```

- `filter` - this property defines fields allowed to filter by, eg URL: `first=john,or+steve`
- `query` - this property defines fields allowed to query by, eg URL: `q=lorem`
- `sort` - this property defines fields allowed to sort by, eg URL: `sort=+first,-age`

`['first' => 'firstName']` in this example `first` is public key (URL) and `firstName` is an Eloquent attribute. You can be more accured and specify the way that query should be performed by using `dot notation`.

- `['first' => 'like.firstName']` = WHERE LIKE statement
- `['category' => 'in.category_id']` = WHERE IN statement
- `['withOutMark' => 'null.mark']` = WHERE NULL statement
- `['posts' => 'has.posts']` = Eloquent has() relation quering
- `['rate' => 'has.reviews.rate']` = Eloquent whereHas() relation quering

You can also use `Mrluke\Searcher\Traits\Searchable` that gives ability to read configuration from class property instead of function.

```
/**
 * Searcher configuration.
 *
 * @var array
 */
protected static $searchableConfig = [];
```

#### Step 2: Controller

[](#step-2-controller)

You can access `Searcher` via Facade `Mrluke\Searcher\Facades\Searcher`. All you need is following line

```
$collection = Searcher::setModel(User::class)->get();
```

##### setModel($model, `Builder` $builder = null) : `self`

[](#setmodelmodel-builder-builder--null--self)

This is main method of package. It is required to perform any action.

- `$model - string|array`
- `$builder - Illuminate\Database\Eloquent\Builder|null`

This method provides ability to setup `Searcher` is tree different ways.

1. Default Model `searchableConfig` with no additional SQL requirements.

```
setModel(string Model::class)
```

2. Default Model `searchableConfig` with custom `Builder` (eg: `whereIn` condition not depended on Url query)

```
setModel(string Model::class, Builder $builder)
```

3. Custom `searchableConfig` passed as 1st argument with Model `Builder` instance.

```
setModel(array $searchableConfig, Builder $builder)
```

By default `Seracher` uses `Illuminate\Http\Request::all()` as an input array.

##### setQuery(`array` $inputs) : `self`

[](#setqueryarray-inputs--self)

This method allows you to set own inputs array instead of using default `Illuminate\Http\Request::all()`

##### setOptions(`array` $options) : `self`

[](#setoptionsarray-options--self)

This method allows you to override default `Searcher` configuration. If you'd like to check all available options see [config file](config/searcher.php).

##### getBuilder() : `Builder`

[](#getbuilder--builder)

This method returns prepared Builder instance for given inputs.

##### get() : `Collection`

[](#get--collection)

This method returns `Illuminate\Support\Collection` for given inputs. If your configuration has property `auto_pagination = true`, it will perform pagination based on `limit` &amp; `offset` inputs.

##### paginate(`int` $limit = null, `int` $offset = null) : `mixed`

[](#paginateint-limit--null-int-offset--null--mixed)

This method allows you to get paginated collection of models. If parameters are not set, method will get them automatically from the inputs. If your configuration has property `api_mode = true`, method will return `Illuminate\Support\Collection` otherwise you will get `Illuminate\Pagination\LengthAwarePaginator`.

Plans
-----

[](#plans)

To be continued...

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Unknown

Total

1

Last Release

2761d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6df8e77a6f4e11408a5658f9127c96ba429354d6ba71a9a5b43966e19455ed17?d=identicon)[mr-luke](/maintainers/mr-luke)

---

Top Contributors

[![mr-luke](https://avatars.githubusercontent.com/u/12121875?v=4)](https://github.com/mr-luke "mr-luke (13 commits)")

---

Tags

eloquentlaravellaravel-5-packagerestsearchinglaravelresteloquentsearching

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mr-luke-searcher/health.svg)

```
[![Health](https://phpackages.com/badges/mr-luke-searcher/health.svg)](https://phpackages.com/packages/mr-luke-searcher)
```

###  Alternatives

[chrisbjr/api-guard

A simple way of authenticating your APIs with API keys using Laravel

698375.6k5](/packages/chrisbjr-api-guard)[api-platform/laravel

API Platform support for Laravel

59126.4k5](/packages/api-platform-laravel)[bjerke/api-query-builder

A query builder for Laravel that parses the request and uses Eloquent ORM to query database

267.7k1](/packages/bjerke-api-query-builder)[bjerke/laravel-bread

A boilerplate package for BREAD operations through REST API in Laravel

115.2k](/packages/bjerke-laravel-bread)[illuminatech/data-provider

Allows easy build for DB queries from API requests

4413.3k](/packages/illuminatech-data-provider)[highsidelabs/laravel-spapi

A Laravel wrapper for Amazon's Selling Partner API (via jlevers/selling-partner-api)

2133.4k](/packages/highsidelabs-laravel-spapi)

PHPackages © 2026

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