PHPackages                             touhidurabir/eloquent-wherelike - 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. touhidurabir/eloquent-wherelike

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

touhidurabir/eloquent-wherelike
===============================

An extended laravel eloquent WHERE method to work with sql LIKE operator.

2.0.1(4y ago)352.5kMITPHPPHP &gt;=7.4

Since Oct 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/touhidurabir/eloquent-wherelike)[ Packagist](https://packagist.org/packages/touhidurabir/eloquent-wherelike)[ RSS](/packages/touhidurabir-eloquent-wherelike/feed)WikiDiscussions master Synced 3d ago

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

Laravel Eloquent WhereLike
==========================

[](#laravel-eloquent-wherelike)

An extended laravel eloquent WHERE method to work with sql LIKE operator.

Inspiration
-----------

[](#inspiration)

The idea of this package comes from one of the [Freek's Blog Post](https://freek.dev/1182-searching-models-using-a-where-like-query-in-laravel). I had developed this macro, which is a slightly different variation of what is described there and using it for years. So I have decided to release this as a package, so that I don't have to copy paste same code again and again and at the same time others can use this to save a little bit of their time.

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

[](#installation)

Require the package using composer:

```
composer require touhidurabir/eloquent-wherelike
```

To publish the config file:

```
php artisan vendor:publish --provider="Touhidurabir\EloquentWherelike\EloquentWherelikeServiceProvider" --tag=config
```

Configurations
--------------

[](#configurations)

The config file contains one important configuration option; the **operator** which defines the SQL operator that will be used to perform the query. By default it's set to **LIKE**, but you can update it as you see fit. For example, for PostgreSQL, it should be set to **ILIKE**.

Usage
-----

[](#usage)

As this **whereLike** method is defined as a **macro**, just use it like any eloquent method.

```
$users = User::whereLike(['email', 'name'], 'search_term')->get();
```

The first param will be the targeted columns to search for and second one is the actual search term.

One big advantage of this package is that is allows searches based on model relations. For example, say a user as one profile, and the profile table has **first\_name** and **last\_name** columns. In order to search users whose first name match, we can do following:

```
$users = User::whereLike(
    [
        'email',
        'name',
        '.profile[first, last_name]'
    ], 'search_term'
)->get();
```

Here, notice the syntax

```
'.profile[first, last_name]'
```

the initial **dot(.)** defines what is the relation, where the **opeing and closing third bracked(\[\])** define the columns of that relation model/table. In this example, we are also looking into the profile relations `first_name` and `last_name` columns.

A more advance example from one of my projects:

```
$campaigns = $campaigns->whereLike(
    [
        'title',
        'description',
        '.user.profile[first_name, last_name]',
        '.categories[name]',
        '.campaigntype[title]',
        '.team[name]'
    ],
    $search
)->get();
```

In the above example, we are searching for all campaigns based on, not only from campaigns table column, but from it's relation models' columns also.

Now, if we want to write the whole thing without using this package, we would have to write:

```
$campaigns = $campaigns->where(function ($query) use ($search) {
    $query
        ->where('title', 'LIKE', '%' . $search . '%')
        ->orWhere('description', 'LIKE', '%' . $search . '%')
        ->orWhereHas('user', function($query) use ($search) {
            $query->whereHas('profile', function($query) use ($search) {
                $query->where('first_name', 'LIKE', '%' . $search . '%')
                ->orWhere('last_name', 'LIKE', '%' . $search . '%');
            });
        })
        ->orWhereHas('categories', function($query) use ($search) {
            $query->where('name', 'LIKE', '%' . $search . '%');
        })
        ->orWhereHas('campaigntype', function($query) use ($search) {
            $query->where('title', 'LIKE', '%' . $search . '%');
        })
        ->orWhereHas('team', function($query) use ($search) {
            $query->where('name', 'LIKE', '%' . $search . '%');
        });
})->get();
```

This **whereLike** saves us so much time this way! 🎉

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

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License
-------

[](#license)

[MIT](./LICENSE.md)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% 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 ~47 days

Total

3

Last Release

1568d ago

Major Versions

1.0.0 → 2.0.02022-01-26

PHP version history (2 changes)1.0.0PHP &gt;=7.2

2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/6c6009d764c48df4a55a8645c349f90a99c7e6e694b06c60b580e1da278d1db5?d=identicon)[touhidurabir](/maintainers/touhidurabir)

---

Top Contributors

[![touhidurabir](https://avatars.githubusercontent.com/u/2587979?v=4)](https://github.com/touhidurabir "touhidurabir (7 commits)")[![zoispag](https://avatars.githubusercontent.com/u/21138205?v=4)](https://github.com/zoispag "zoispag (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/touhidurabir-eloquent-wherelike/health.svg)

```
[![Health](https://phpackages.com/badges/touhidurabir-eloquent-wherelike/health.svg)](https://phpackages.com/packages/touhidurabir-eloquent-wherelike)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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