PHPackages                             muhaimenul/lara-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. [Database &amp; ORM](/categories/database)
4. /
5. muhaimenul/lara-search

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

muhaimenul/lara-search
======================

An eloquent model searching package with various searching configuration.

1.0.0(7y ago)1385[2 PRs](https://github.com/muhaimenul/lara-search/pulls)MITPHP

Since Feb 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/muhaimenul/lara-search)[ Packagist](https://packagist.org/packages/muhaimenul/lara-search)[ RSS](/packages/muhaimenul-lara-search/feed)WikiDiscussions master Synced today

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

[![](https://camo.githubusercontent.com/c71033020cc31045406d70130c269b083f9f3033ce36517bd3a44dad607aaf87/68747470733a2f2f696d672e69636f6e73382e636f6d2f636f6c6f722f34382f3030303030302f7365617263682e706e67)](https://camo.githubusercontent.com/c71033020cc31045406d70130c269b083f9f3033ce36517bd3a44dad607aaf87/68747470733a2f2f696d672e69636f6e73382e636f6d2f636f6c6f722f34382f3030303030302f7365617263682e706e67)LaraSearch
================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#larasearch)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e5a91834d26c6e7e036afcdbd7960466fd48fd42618a594ba437a996f915781c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d756861696d656e756c2f6c6172612d7365617263682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/muhaimenul/lara-search)[![Total Downloads](https://camo.githubusercontent.com/8c27650a22bb78f62eda126a30666263b9be9abedc76eda766b99f1eae8e21bc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d756861696d656e756c2f6c6172612d7365617263682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/muhaimenul/lara-search)[![GitHub license](https://camo.githubusercontent.com/2c35df2da25b9f18c8db9916b00354a485470a77c6b52eeaa3c9ca691c64f259/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d6f72616e67652e737667)](https://raw.githubusercontent.com/muhaimenul/lara-crud/master/LICENSE)[![Awesome Laravel](https://camo.githubusercontent.com/8deb0d78e81ca47c3c3533bd8de23d75fa7a6f4f3e8fb067f246c42e62a8d06a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f417765736f6d652d4c61726176656c2d627269676874677265656e2e737667)](https://github.com/muhaimenul/lara-search)

About LaraSearch (Laravel Search)
---------------------------------

[](#about-larasearch-laravel-search)

LaraSearch (Laravel Search) is a Laravel package that adds various searching functionalities to Eloquent Models. This package makes it easy to get structured search from a variety of sources and provides varieties of configurations and options to select for searching, such as:

- [Simple search](#simple)
- [MySQL Full-text search](#fts)
- Elastic like search (Future Improvement)

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

[](#installation)

You can install the package via composer:

```
composer require muhaimenul/lara-search
```

Usage

-------

[](#usage)

### Preparing your models

[](#preparing-your-models)

Add the `LaraSearch` trait to your model and `$searchable` columns as your search rules.

```
use Muhaimenul\Larasearch\Traits\LaraSearch;

class User extends Model
{
    use LaraSearch;

    /**
     * Columns that are considered for search results.
     *
     * @var array
     */
    protected $searchable = [
        'first_name', 'last_name', 'email'
    ];
}
```

### Searching models

[](#searching-models)

With the models prepared you can search them like this:

```
// search string
$queryString = 'xyz';

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

// Search and get relations
// It will not get the relations if you don't do this
$users = User::search($queryString)
            ->with('posts')
            ->get();
```

#### Search like default queries

[](#search-like-default-queries)

This Search methos is compatable with any eloquent methods and Paginatation like laravel default queries. Such as,

```
// Search with relations and pagination
$users = User::search($queryString)
            ->with('posts')
            ->paginate(20);

// Search only active users check
$users = User::where('status', 'active')
            ->search($queryString)
            ->paginate(20);
```

Simple Search

---------------

[](#simple-search)

Simple search uses eloquent WHERE and sql LIKE operator to search for a specified pattern in a column. By default, this package uses it and No additional configuration is needed. Just follow above [instructions](#usage) to use Simple Search.

MySQL Full-text Search

------------------------

[](#mysql-full-text-search)

Full-Text Search in MySQL server lets users run full-text queries against character-based data in MySQL tables. It is a powerful features that allows searching text efficiently accross multiple columns. It provides searching functionalites like Algolia but more native to MySQL. To learn more [see here](https://www.w3resource.com/mysql/mysql-full-text-search-functions.php). From version 4, Laravel doesn't support FULLTEXT indexes by default. So, a [full-text index](#ftindex) must be created on the table before running full-text queries on a table.

If you want to use it, then you will have to publish to package in order to enable it from config.

Publishing
----------

[](#publishing)

You can publish everything at once:

```
php artisan vendor:publish --provider="muhaimenul\larasearch\LarasearchServiceProvider"
```

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

[](#configuration)

After publishing the package you will find, `larasearch.php` configuration file in the `config` folder.

Here, the '`formula`' is the key to determine this project's search type. Currently there are two types of configuration, '`fulltext`' (FullText Search) and '`like`' (Simple Search).

```
// fulltext or like
    'formula' => env('LARA_SEARCH_TYPE', 'fulltext'),
```

You can directly assign formula type in `larasearch.php` or use `.env` and assign value to 'LARA\_SEARCH\_TYPE' alias.

By default, this package uses [Simple Search](#simple), which doesn't need any publishing or additional configuration. But to use [FullText Search](#fts), you have to publish the package and follow below configuration.

 Setup Full-Text Search

-------------------------

[](#-setup-full-text-search)

To use Full-text search, only additional full-text index is needed. Rest of the searching process is same.

- Fulltext search can only be used with MySQL 5.6+, else the Database Engine must be set to MyISAM instead of InnoDB.
- Then set up the migration and add the Full-Text index.

```
public function up()
{
    Schema::table('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('first_name');
        $table->string('last_name');
        $table->string('email')->unique();
    });

    // Full Text Index
    DB::statement('ALTER TABLE users ADD FULLTEXT fulltext_index (first_name, last_name, email)');
}
```

NOTE: Here, `fulltext_index (first_name, last_name, email)` must have to be same as the `protected $searchable` columns / array added in the model.

Then, run the migrations.

```
php artisan migrate

```

Voalá! The setup is done. Now The powrfull fulltext search can be used easily by this package following the initial [usage](#usage).

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability or bugs within LaraSearch, please send an e-mail to Muhaimenul Islam via .

Credits
-------

[](#credits)

- [Muhaimenul Islam](https://github.com/muhaimenul)

License
-------

[](#license)

The LaraSearch package is open-sourced project licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 95.6% 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

2637d ago

### Community

Maintainers

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

---

Top Contributors

[![muhaimenul](https://avatars.githubusercontent.com/u/32401626?v=4)](https://github.com/muhaimenul "muhaimenul (43 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

searchlaraveldatabasemodeleloquentsearchablefull-textlarasearchmuhaimenul

### Embed Badge

![Health badge](/badges/muhaimenul-lara-search/health.svg)

```
[![Health](https://phpackages.com/badges/muhaimenul-lara-search/health.svg)](https://phpackages.com/packages/muhaimenul-lara-search)
```

###  Alternatives

[nicolaslopezj/searchable

Eloquent model search trait.

2.0k2.7M35](/packages/nicolaslopezj-searchable)

PHPackages © 2026

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