PHPackages                             filipac/searchable - 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. filipac/searchable

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

filipac/searchable
==================

Eloquent model search trait.

1.0.0(11y ago)224MITPHPPHP &gt;=5.4.0

Since Sep 15Pushed 11y ago1 watchersCompare

[ Source](https://github.com/filipac/searchable)[ Packagist](https://packagist.org/packages/filipac/searchable)[ RSS](/packages/filipac-searchable/feed)WikiDiscussions master Synced 1w ago

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

Searchable, a search trait for Laravel
======================================

[](#searchable-a-search-trait-for-laravel)

[![Filipac/searchable](https://raw.githubusercontent.com/filipac/searchable/master/searchable.jpg)](https://raw.githubusercontent.com/filipac/searchable/master/searchable.jpg)

Searchable is a trait for Laravel 4.2+ that adds a simple search function to Eloquent Models.

Searchable allows custom columns and relevance for each model.

Installation
============

[](#installation)

Simply add the package to your `composer.json` file and run `composer update`.

```
"filipac/searchable": "1.0.*"

```

Usage
-----

[](#usage)

Add the trait to your model and your search rules.

```
use Filipac\Searchable\SearchableTrait;

class User extends \Eloquent
{
	use SearchableTrait;

    /**
     * Searchable rules.
     *
     * @var array
     */
    protected $searchable = [
        ['column' => 'first_name', 'relevance' => 10],
        ['column' => 'last_name', 'relevance' => 10],
        ['column' => 'bio', 'relevance' => 2],
        ['column' => 'email', 'relevance' => 5],
    ];
}
```

Now you can search your model.

```
// Simple search
$users = User::search($query)->get();

// Search and get relations
$users = User::search($query)
->with('photos')
->get();
```

Search Paginated
----------------

[](#search-paginated)

Laravel default pagination doesn't work with this, you have to do it this way

```
// This class is required
use Filipac\Searchable\DBHelper;
```

```
// Get the current page values
$page = Input::get('page') ? Input::get('page') : 1;
$count = Input::get('count') ? Input::get('count') : 20; // items per page
$from = 1 + $count * ($page - 1);

// Perform the search
$data = User::search($query)
->take($count)
->skip($from - 1)
->get()
->toArray();

// Get the count of rows of the last query
$db_query_log = DB::getQueryLog();
$db_query = end($db_query_log);
$total_items = DBHelper::getQueryCount($db_query);

// Create the paginator
$users = Paginator::make($data, $total_items, $count);
```

If you want to search through relations too, you can add the following to the desired model:

```
protected $joinable = [
    'profiles' => ['users.profile_id','profiles.id']
    ];
```

The code above would join the `profiles` table on `users.profile_id = profiles.id`. Then you can add the following to search in profiles table:

```
/**
     * Searchable rules.
     *
     * @var array
     */
    protected $searchable = [
        ['column' => 'name', 'relevance' => 10],
        ['column' => 'profiles.name', 'relevance' => 1],
        ['column' => 'profiles.description', 'relevance' => 2],
    ];
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

4261d ago

### Community

Maintainers

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

---

Top Contributors

[![filipac](https://avatars.githubusercontent.com/u/271155?v=4)](https://github.com/filipac "filipac (6 commits)")

---

Tags

searchlaraveleloquentsearchable

### Embed Badge

![Health badge](/badges/filipac-searchable/health.svg)

```
[![Health](https://phpackages.com/badges/filipac-searchable/health.svg)](https://phpackages.com/packages/filipac-searchable)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[jedrzej/searchable

Searchable trait for Laravel's Eloquent models - filter your models using request parameters

127259.1k5](/packages/jedrzej-searchable)

PHPackages © 2026

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