PHPackages                             astritzeqiri/laravel-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. [Search &amp; Filtering](/categories/search)
4. /
5. astritzeqiri/laravel-searchable

ActiveLaravel-plugin[Search &amp; Filtering](/categories/search)

astritzeqiri/laravel-searchable
===============================

A php trait for searching on laravel eloquent models

1.0.2(9y ago)3202MITPHPPHP &gt;=5.4.0

Since Feb 28Pushed 8y ago1 watchersCompare

[ Source](https://github.com/astritzeqiri/laravel-searchable)[ Packagist](https://packagist.org/packages/astritzeqiri/laravel-searchable)[ Docs](https://github.com/astritzeqiri/laravel-searchable)[ RSS](/packages/astritzeqiri-laravel-searchable/feed)WikiDiscussions master Synced 2mo ago

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

Laravel Searchable
==================

[](#laravel-searchable)

A php trait for searching on laravel eloquent models

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

[](#requirements)

- PHP &gt;= 5.4
- Laravel &gt;= 5.0

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

[](#installation)

Add laravel-searchable to your composer.json file:

```
"require": {
    "astritzeqiri/laravel-searchable": "~1.0"
}
```

Get composer to install the package:

```
$ composer require astritzeqiri/laravel-searchable

```

Usage
-----

[](#usage)

### Examples

[](#examples)

First you need to go to your model and use the Searchable:

```
// E.x. User.php
// add this before the class declaration
use AstritZeqiri\LaravelSearchable\Traits\Searchable;

// after the class declaration add this code snippet:
use Searchable;
```

Basic search:

```
// This gives you a list of users that match the name john
$users = App\User::search('John', ['name'])->get();

// if you want the search to be exact you pass a third attribute
$users = App\User::search('John', ['name'], true)->get();
```

The array of search fields can also be set on the Model itself E.x. User.php:

```
class User extends Model
{
    // These are the default search fields.
    protected static $searchOn = ['first_name', 'last_name'];

}

// Now you can do this.
// That gives you the users with the first_name or last_name Doe
$users = App\User::search('Doe')->get();

// Of course if you give it the second attribute it ignores the model fields.
// Now it only searches on the first_name not the last_name
$users = App\User::search('Doe', ['first_name'])->get();
```

Sometimes you may want to search on some other fields that are not on the user model but in some other table related to the user:

```
// Ex. You want to search users profile description which is contained in the profiles table,
// you can do that by giving for example profile_description asf field.
$users = App\User::search('Texas', ['profile_description'])->get();

// And then you'll have to declare a scope function on you User model for that field.
// The function has to be called 'scopeSearchOn' and your field on studly_case
// in this example it needs to be 'scopeSearchOnProfileDescription'
class User extends Model
{
    /**
     * Search on the users profile description.
     *
     * @param  QueryBuilder $query
     * @param  string $search [the string that we are searching for]
     * @param  string $exact [if exact searching has been required]
     *
     * @return QueryBuilder $query
     */
    public function scopeSearchOnProfileDescription($query, $search, $exact)
    {
        return $query->whereHas('profile', function($query) use($search) {
            return $query->where('description', 'LIKE', $search);
        });
    }

}
```

License
-------

[](#license)

[MIT](http://opensource.org/licenses/MIT)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

3359d ago

### Community

Maintainers

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

---

Top Contributors

[![astritzeqiri](https://avatars.githubusercontent.com/u/8720176?v=4)](https://github.com/astritzeqiri "astritzeqiri (10 commits)")

---

Tags

eloquent-modelseloquent-searchlaravellaravel-5-packagesearchsearchlaravellarave-search

### Embed Badge

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

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

###  Alternatives

[romangrinev/laravel-opensearch-engine

Custom Laravel Scout OpenSearch Engine

1319.8k](/packages/romangrinev-laravel-opensearch-engine)[omure/scout-advanced-meilisearch

Laravel Scout extension that allows to use meilisearch advanced features as well as has an extended collection driver for testing purposes.

123.9k](/packages/omure-scout-advanced-meilisearch)

PHPackages © 2026

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