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

ActiveLibrary[Search &amp; Filtering](/categories/search)

illusi03/lara-search
====================

Advanced model and relationships search for Laravel

v1.6.2(4y ago)0143MITPHP

Since Oct 4Pushed 4y ago1 watchersCompare

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

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

LaraSearch for Laravel
----------------------

[](#larasearch-for-laravel)

LaraSearch is a search package for laravel that use recursivity to efficiently find a record of a model, by occurrences of any word found in the search and in any relationship given for the model.

Let's say you have a model Post, the model Post hasMany comments, and the model Comment belongsTo a User. Beside, your app user searched for the string "Galactic Empire,and... pizza for steve".

Yup, that makes sense. If you want to find a post given that string in any part of the relationship chain of the Post model it could, for example:

- bring a post which title is "The love for pizza".
- bring a post that has a comment that says "Wow that was out of this empire"
- bring a post that has a comment posted by a guy named "Steve". Hi Steve.

### Installation

[](#installation)

Require the package in your composer.json and update composer to download the package

```
composer require illusi03/lara-search

```

After that, add the ServiceProvider to the providers array in config/app.php

```
Illusi03\LaraSearch\ServiceProvider::class,
```

if you want to, add the facade for convenience

```
'LaraSearch' => Illusi03\LaraSearchFacade::class,
```

How to Use
----------

[](#how-to-use)

### Using the trait

[](#using-the-trait)

Use the trait in your model

```
use Illusi03\LaraSearch\Traits\LaraSearchable;

class Model extends Eloquent {

    use LaraSearchable;

    ...
}
```

The LaraSearch() method will bring back your search results. It takes 3 arguments:

- **$search** the search string to find
- **$fields** an array with the fields of the model you want to search in
- **$relationFields** an associative array with the relations of the main model and their fields you want to search in

```
$posts = Post::laraSearch($userInput, ['title'], [
    'comments' => 'comment',
    'comments.user' => ['name', 'lastname']
])->get();
```

### Using the static class

[](#using-the-static-class)

Alternatively you can use the static class LaraSearch::find(). It takes 3 arguments:

- **$search** the search string to find
- **$model** the model from which you want to return the records. ex: 'App\\Post'
- **$searchSchema** an array with the relations of the main model you want to search in, as well as what fields. The format is as follows:

```
$searchSchema = [
    'fields' => ['title'], // Fields where you want to search in the main model
    'relationships' => [ // Relationships, if any
        [
            'relationship' => 'comments', // Here you put name of the relationship
            'fields' => 'comment', // And here the fields where you want to search in the related table
        ],
        [
            'relationship' => 'comments.user', // Use dot notation for inner relations
            'fields' => ['name', 'lastname'],
        ]
    ]
];
```

### Chaining

[](#chaining)

The LaraSearch() and find() methods return a query, so you need to bring the results by yourself using get() or paginate(n) and even chaining other methods. Following the example above we get:

```
$search = LaraSearch::find($userInput, App\Models\Post::query(), $searchSchema)->where('active', 1)->paginate(10);
```

Authors
-------

[](#authors)

- **lHumanizado**
- **Rubenazo**
- **Illusi03**

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

7

Last Release

1679d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3557e8e65ca0e204ffe60f1768a756ae27012ba7b09c7081fc39fe295887e079?d=identicon)[illusi03](/maintainers/illusi03)

---

Top Contributors

[![illusi03](https://avatars.githubusercontent.com/u/52351532?v=4)](https://github.com/illusi03 "illusi03 (7 commits)")

### Embed Badge

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

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

###  Alternatives

[mehradsadeghi/laravel-filter-querystring

Filter your queries based on url query string parameters like a breeze.

169118.2k](/packages/mehradsadeghi-laravel-filter-querystring)[pos-lifestyle/laravel-nova-date-range-filter

A Laravel Nova date range filter.

16179.1k](/packages/pos-lifestyle-laravel-nova-date-range-filter)[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)
