PHPackages                             aviator/eloquent-search-map - 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. aviator/eloquent-search-map

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

aviator/eloquent-search-map
===========================

An Eloquent search macro for effortlessly searching models

0.1.1(8y ago)11.9k↑500%MITPHPPHP &gt;=7.0.0

Since Nov 28Pushed 8y ago1 watchersCompare

[ Source](https://github.com/danielsdeboer/eloquent-search-map)[ Packagist](https://packagist.org/packages/aviator/eloquent-search-map)[ Docs](https://github.com/danielsdeboer/eloquent-search-map)[ RSS](/packages/aviator-eloquent-search-map/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/4658f5bd487a244868d330ca4fd8344e24522fb867e5edad72bc7e1e2850670c/68747470733a2f2f7472617669732d63692e6f72672f64616e69656c736465626f65722f656c6f7175656e742d7365617263682d6d61702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/danielsdeboer/eloquent-search-map)[![Latest Stable Version](https://camo.githubusercontent.com/e2e24cd9f98b683ca26ab2e0cd06cee30146aca9811818a7834b91b94049e49b/68747470733a2f2f706f7365722e707567782e6f72672f61766961746f722f656c6f7175656e742d7365617263682d6d61702f762f737461626c65)](https://packagist.org/packages/aviator/eloquent-search-map)[![License](https://camo.githubusercontent.com/d3f8511fac3821806dc4e904129f399ae221966ee74fb6b4716c93f6c72c0319/68747470733a2f2f706f7365722e707567782e6f72672f61766961746f722f656c6f7175656e742d7365617263682d6d61702f6c6963656e7365)](https://packagist.org/packages/aviator/eloquent-search-map)

Overview
--------

[](#overview)

Add Eloquent query search constraints effortlessly with this Eloquent macro.

This is especially handy when you find yourself building simple, optional searches often:

```
$model::when($request->something, function (Builder $query) {
    return $query->where('column', 'like', '%' . $request->something . '%');
})->get();
```

With this package you can do this instead:

```
$model::search(['something', 'otherthing'])->get();
```

You may create an optional column map on your model, as well as mapping request properties on the fly.

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

[](#installation)

Via Composer:

```
composer require aviator/eloquent-search-map

```

In your `config/app.php` add `Aviator\Search\ServiceProvider::class` to the `providers` array:

```
'providers' => [
    ...
    Aviator\Search\ServiceProvider::class,
],
```

Testing
-------

[](#testing)

Via Composer:

```
composer test

```

Usage
-----

[](#usage)

### Model Setup

[](#model-setup)

To start, make the model you want to search implement the `Searchable` contract and use the `SearchableTrait`.

```
class User extends Model implements Searchable
{
    use SearchableTrait;

    // ..etc
}
```

Then set a `searches` array property on your model containing your searchable columns. To search in the email column using `$model::search(['email'])`:

```
protected $searches = [
    'email'
];
```

To search in the email column using $model::search(\['alias'\])

```
protected $searches = [
    'alias' => 'email'
];
```

### Request Aliases

[](#request-aliases)

By default, the search builder assumes the column name or alias matches the request data. So if you call `$model::search(['something'])`, it will look for `request('something')`.

Of course you can specify the request property name manually:

```
$model::search(['email' => 'user_email'])->get();
```

This tells the search builder to look for the `email` request data in `request('user_email')` instead of the default.

### Custom Requests

[](#custom-requests)

If you need to pass a custom request into the macro, use the second parameter, which accepts an object extending `Illuminate\Http\Request`:

```
$model::search(['term'], $request)->get();
```

Of course, this is completely optional. If a request isn't provided, it will be retrieved from the container.

### Related Models

[](#related-models)

If you want to query related models, you can! Use dot notation:

```
protected $searches = [
    'relation.column'
];
```

This will look for a relation method called `company()` and add a `whereHas` constraint to the query. For instance:

```
$users = User::search(['company.city'])->get();
```

This will look on the `User` model for a relation `company()` and search in the `city` attribute of that model.

By default we assume that the request will have the same property, snake cased. For the above query constraint the search builder will look for `request('company_city')`.

This can also be mapped:

```
$users = User::search(['company.city' => 'city'])->get();
```

The search builder will now look for `request('city')` instead.

Other Stuff
-----------

[](#other-stuff)

### License

[](#license)

This package is licensed with the [MIT License (MIT)](LICENSE).

###  Health Score

27

—

LowBetter than 51% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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 ~0 days

Total

2

Last Release

3037d ago

### Community

Maintainers

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

---

Top Contributors

[![danielsdeboer](https://avatars.githubusercontent.com/u/13170241?v=4)](https://github.com/danielsdeboer "danielsdeboer (12 commits)")

---

Tags

eloquentlaravelphpphp7searchphpsearchlaraveleloquentPHP7

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aviator-eloquent-search-map/health.svg)

```
[![Health](https://phpackages.com/badges/aviator-eloquent-search-map/health.svg)](https://phpackages.com/packages/aviator-eloquent-search-map)
```

###  Alternatives

[lacodix/laravel-model-filter

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

17648.2k](/packages/lacodix-laravel-model-filter)[matchory/elasticsearch

The missing elasticsearch ORM for Laravel!

3057.6k](/packages/matchory-elasticsearch)[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3410.3k3](/packages/wayofdev-laravel-cycle-orm-adapter)[salehhashemi/laravel-repository

Implementing the repository pattern for Laravel projects.

2010.5k](/packages/salehhashemi-laravel-repository)

PHPackages © 2026

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