PHPackages                             asseco-voice/laravel-json-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. asseco-voice/laravel-json-search

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

asseco-voice/laravel-json-search
================================

Laravel JSON search

v7.1.1(5mo ago)77.3k↓100%[1 PRs](https://github.com/asseco-voice/laravel-json-search/pulls)MITPHPPHP ^8.1CI passing

Since Feb 10Pushed 5mo ago6 watchersCompare

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

READMEChangelogDependencies (7)Versions (40)Used By (0)

[![](https://github.com/asseco-voice/art/raw/main/evil_logo.png)](https://see.asseco.com)

Laravel JSON search
===================

[](#laravel-json-search)

This package exposes a `jsonSearch` method on Laravel Eloquent models providing a detailed DB search with JSON as input parameter.

It functions out-of-the-box automatically for all Eloquent models within the project. No additional setup is needed.

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

[](#installation)

Install the package through composer. It is automatically registered as a Laravel service provider, so no additional actions are required.

`composer require asseco-voice/laravel-json-search`

Usage
-----

[](#usage)

Package provides few endpoints out of the box:

- [POST](#post) `/api/search/{model}` - for search
- [PUT](#put) `/api/search/{model}/update` - for mass update by query results
- [DELETE](#delete) `/api/search/{model}` - for mass delete by query results

Model should be provided in standard Laravel notation (lowercase plural) in order to map it automatically (i.e. `/api/search/contacts` in order to search `Contact` model).

By default, `App` namespace is used, but you can change the defaults or add additional endpoints if you have need for that in the [package configuration](#configuration) by either adding a direct model mapping in `model_mapping` key (taking precedence over other options), or adding additional values to `models_namespaces` array to make it more generic.

Description on how to use each of those are in the configuration file.

If out-of-the-box solutions don't suit you, feel free to implement the logic directly within your controller. For details check out [custom endpoints section](#custom-endpoints).

Following are some examples, however there is **much more** to the search package than just filtering by attributes.

**For detailed engine usage and logic, refer to [this readme](https://github.com/asseco-voice/laravel-json-query-builder).**

Examples
--------

[](#examples)

### POST

[](#post)

Call the endpoint providing the following JSON:

```
{
    "search": {
        "first_name": "=foo;bar;!baz",
        "last_name": "=test"
    }
}
```

This will perform a `SELECT * FROM some_table WHERE first_name IN ('foo, 'bar')  AND first_name not in ('baz') or last_name in ('test')`.

Additionally, you are able to provide `append` array to resolve your custom defined properties on a Laravel model which aren't listed in `$appends` array. I.e.

```
public function getSomeAttribute()
{
    return 'foo';
}
```

You can return it by using:

```
{
    "search": {
        "first_name": "=foo;bar;!baz",
        "last_name": "=test"
    },
    "append": ["some"]
}
```

It is possible to do 1-level nested appends like:

```
"append": ["relation1.append_attribute_for_r1"]

```

More than 1-level is not supported.

Do note that this is completely unoptimized and will potentially cause really slow executions. Use with caution.

### PUT

[](#put)

Call the endpoint providing the following JSON:

```
{
    "search": {
        "first_name": "=foo;bar;!baz",
        "last_name": "=test"
    },
    "update": {
        "first_name": "new name"
    }
}
```

This will perform a `SELECT * FROM some_table WHERE first_name IN ('foo, 'bar')  AND first_name not in ('baz') or last_name in ('test')`, and on the given result set it will perform a mass update giving a `new name` to every record retrieved

### DELETE

[](#delete)

```
{
    "search": {
        "first_name": "=foo;bar;!baz",
        "last_name": "=test"
    }
}
```

This will perform a `DELETE FROM some_table WHERE first_name IN ('foo, 'bar')  AND first_name not in ('baz') or last_name in ('test')` doing a mass delete by given parameters.

Custom endpoints
----------------

[](#custom-endpoints)

It is possible to create a custom endpoint if the current setup does not suit you.

### Search

[](#search)

- Add route:

```
Route::post('search', 'ExampleController@search');
```

- Call the method within the controller and provide it with input parameters from JSON body.

```
public function search(Request $request)
{
    return SomeModel::jsonSearch($request->all())->get();
}
```

### Update

[](#update)

- Add route:

```
Route::put('search/update', 'ExampleController@search');
```

- Call the method within the controller and provide it with input parameters from JSON body.

```
public function search(Request $request)
{
    $search = SomeModel::jsonSearch($request->except('update'));

    if (!$request->has('update')) {
        throw new Exception('Missing update parameters');
    }

    $search->update($request->update);

    return $search->get();
}
```

### Delete

[](#delete-1)

- Add route:

```
Route::delete('search', 'ExampleController@search');
```

- Call the method within the controller and provide it with input parameters from JSON body.

```
public function search(Request $request)
{
    return SomeModel::jsonSearch($request->all())->delete();
}
```

Search favorites
----------------

[](#search-favorites)

Favorites enable you to save searches for a specific user.

Usage:

1. Run `php artisan migrate`.
2. Use through standard laravel API resource routes on `/api/search-favorites` URL.
3. If you need to modify migrations [publish the package](#configuration) and set `runs_migrations`property in the config file to `false`.
4. Set authorizeResource in asseco-search to false if you do not want $this-&gt;authorizeResource(SearchFavorite::class) to be added in controller.

It is possible to extend the model used for search favorites and replace with your own. Make sure your model extends `SearchFavorite` and replace `search_favorite_model` key in the configuration with your model.

Search - paginated
------------------

[](#search---paginated)

```
POST  https://service.url/api/search-paginated/:model

```

Request:

```
{
    "page": 2,
    "limit": 10,
    "search": [ .... ]
}

```

Response:

```
{
    "data": [ ... ],
    "metadata": {
        "page": 2,
        "limit": 10,
        "count": 10,
        "total_count": 145
    }
}

```

Debugging
---------

[](#debugging)

If you'd like to see query called instead of a result, uncomment `dump` line within `Asseco\JsonSearch\SearchServiceProvider`.

Due to Laravel query builder inner workings, this will not dump the resulting query for relations. For that purpose I'd recommend using Laravel query log.

Extending the package
=====================

[](#extending-the-package)

Publishing the configuration will enable you to change package models as well as controlling how migrations behave. If extending the model, make sure you're extending the original model in your implementation.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance72

Regular maintenance activity

Popularity26

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

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

Recently: every ~135 days

Total

38

Last Release

155d ago

Major Versions

v2.9.0 → v3.0.02022-05-05

v3.0.0 → v4.0.02022-07-14

v4.1.0 → v5.0.02022-09-13

v5.1.1 → v6.0.02023-03-24

v6.1.0 → v7.0.02023-08-08

PHP version history (4 changes)v0.1.0PHP ^7.4

v0.2.0PHP ^7.4 || ^8.0

v3.0.0PHP ^8.0

v7.0.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![Norgul](https://avatars.githubusercontent.com/u/11718157?v=4)](https://github.com/Norgul "Norgul (56 commits)")[![josip-milotic](https://avatars.githubusercontent.com/u/42002911?v=4)](https://github.com/josip-milotic "josip-milotic (10 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![DaveXo9](https://avatars.githubusercontent.com/u/85836822?v=4)](https://github.com/DaveXo9 "DaveXo9 (3 commits)")[![ngaspari](https://avatars.githubusercontent.com/u/33628128?v=4)](https://github.com/ngaspari "ngaspari (2 commits)")[![assefvisic](https://avatars.githubusercontent.com/u/60132037?v=4)](https://github.com/assefvisic "assefvisic (1 commits)")

---

Tags

buildereloquenteloquent-modelslaravellaravel-8-packagelaravel-frameworklaravel-packagemicroservicemicroservicesphpquerysearchphplaravel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/asseco-voice-laravel-json-search/health.svg)

```
[![Health](https://phpackages.com/badges/asseco-voice-laravel-json-search/health.svg)](https://phpackages.com/packages/asseco-voice-laravel-json-search)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[umbrellio/laravel-ltree

Extension LTree (Postgres) for Laravel

34111.6k](/packages/umbrellio-laravel-ltree)[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3516.7k3](/packages/wayofdev-laravel-cycle-orm-adapter)[salehhashemi/laravel-repository

Implementing the repository pattern for Laravel projects.

2010.5k](/packages/salehhashemi-laravel-repository)

PHPackages © 2026

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