PHPackages                             cuongnd88/lara-query-kit - 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. cuongnd88/lara-query-kit

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

cuongnd88/lara-query-kit
========================

Lara Query Kit utilizes the Eloquent model

1.2.1(4y ago)37011MITPHP

Since Jul 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/cuongnd88/lara-query-kit)[ Packagist](https://packagist.org/packages/cuongnd88/lara-query-kit)[ Docs](https://github.com/cuongnd88/lara-query-kit)[ RSS](/packages/cuongnd88-lara-query-kit/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (5)DependenciesVersions (6)Used By (1)

Lara Query Kit
==============

[](#lara-query-kit)

Lara Query Kit utilizes the Eloquent model. PHP Trait and Laravel local scope are used to implement this utilitiy

### PHP Traits

[](#php-traits)

PHP only supports single inheritance: a child class can inherit only from one single parent.

So, what if a class needs to inherit multiple behaviors? OOP traits solve this problem.

Traits are used to declare methods that can be used in multiple classes. Traits can have methods and abstract methods that can be used in multiple classes, and the methods can have any access modifier (public, private, or protected).

### Laravel local scope

[](#laravel-local-scope)

Local scopes allow you to define common sets of constraints that you may easily re-use throughout your application. To define a scope, simply prefix an Eloquent model method with `scope`.

Installation &amp; Configuration
--------------------------------

[](#installation--configuration)

1-Install `cuongnd88/lara-query-kit` using Composer.

```
	composer require cuongnd88/lara-query-kit
```

2-Push `lara-query-kit` into your application.

```
	php artisan vendor:publish --provider="Cuongnd88\LaraQueryKit\LaraQueryKitServiceProvider"
```

3-`App\Traits\QueryKit.php` is already to pump your performance. Please add `QueryKit` into the model

```
. . . .
use App\Traits\QueryKit;

class User extends Authenticatable
{
    use Notifiable;
    use HasOtpAuth;
    use HasGuardian;
    use QueryKit;

. . . .
}
```

Available methods
-----------------

[](#available-methods)

Let discuss each method available on the Query Kit.

- [insertDuplicate()](#insertDuplicate)
- [getTableColumns()](#getTableColumns)
- [exclude()](#exclude)
- [filter()](#filter)
- [searchFulltext()](#searchFulltext)

### insertDuplicate

[](#insertduplicate)

*`insertDuplicate(array $data, array $insertKeys, array $updateKeys)`: Insert new rows or update existed rows.*

```
    public function upsert()
    {
        $data = [
            ['name' => "Dean Ngo", 'email' => 'dinhcuongngo@gmail.com', 'mobile' => '84905005533', 'password' => Hash::make('123456')],
            ['name' => "Robert Neil", 'email' => '1111@gmail.com', 'mobile' => '84905001122', 'password' => Hash::make('123456')],
        ];
        User::insertDuplicate($data, ['name', 'email', 'mobile', 'password'], ['name', 'email', 'mobile']);
    }
```

### getTableColumns

[](#gettablecolumns)

*`getTableColumns()`: Get the array of columns.*

```
    public function listTableColumns()
    {
        $columns = User::getTableColumns();
        dump($columns);
    }
```

### exclude

[](#exclude)

*`exclude(array $columns)`: Retrieve a subset of the output data.*

You should define which model attributes you want to exclude. You may do this using the `$excludable` property on the model.

```
. . . .
use App\Traits\QueryKit;

class User extends Authenticatable
{
    use Notifiable;
    use HasOtpAuth;
    use HasGuardian;
    use QueryKit;

    protected $excludable = ['deleted_at', 'created_at', 'updated_at'];

. . . .
}
```

```
    public function listUsers()
    {
        $data = User::exclude()->get()->toArray();
        dump($data);
    }
```

Or pass a array of excludable columns as argument

```
    public function listUsers()
    {
        $users = User::exclude(['deleted_at', 'created_at', 'updated_at'])
                        ->get()->toArray();
        dump($users);
    }
```

### filter

[](#filter)

*`filter(array $params)`: Get the result with filter conditions.*

You may use the `fitler` method on a query builder instance to add `where` clauses to the query. The `$filterable` property should contain an array of conditions that you want to execute searching. The key of filterable array corresponds to table columns, whereas the value is condition to call `where` clauses. The most basic condition requires two arguments:

- The first argument is simple where clause such as: where, orWhere, whereBetween, whereNotBetween, whereIn, whereNotIn, whereNull, whereNotNull, orWhereNull , orWhereNotNull, whereDate, whereMonth, whereDay, whereYear, whereTime
- The second argument is an operator, which can be any of the database's supported operators.

Exceptionally, the third argument is required with the `operator` is `LIKE`, it is for a specified pattern

For convenience, if you verify only column in `fiterable` property, the default clause is `where` with `=` operator

```
. . . .
use App\Traits\QueryKit;

class User extends Authenticatable
{
    use Notifiable;
    use HasOtpAuth;
    use HasGuardian;
    use QueryKit;

    protected $filterable = [
        'id' => ['whereBetween'],
        'email',
        'name' => ['orWhere', 'LIKE', '%{name}%'],
    ];

. . . .
}
```

```
    public function filter()
    {
        $where = [
            'id' => [1,5],
            'email' => 'dinhcuongngo@gmail.com',
            'name' => 'ngo',
        ];

        $data = User::->filter($where)->get()->toArray();
    }
```

Dynamically, you can call `filterableCondition()` and assign the filterable conditions

```
    public function filter()
    {
        $filterable = [
            'email',
            'name' => ['orWhere', 'LIKE', '%{name}%'],
            'deleted_at' => ['whereNull'],
        ];

        $where = [
            'email' => 'dinhcuongngo@gmail.com',
            'name' => 'ngo',
            'deleted_at' => '',
        ];

        $data = User::filterableCondition($filterable)
                        ->filter($where)
                        ->get()
                        ->toArray();
    }
```

### searchFulltext

[](#searchfulltext)

*`searchFulltext($value, $mode = NATURAL_LANGUAGE)`: Run full-text queries against character-based data in MySQL tables.*

There are four modes of full-text searches:

- `NATURAL_LANGUAGE` (is default): IN NATURAL LANGUAGE MODE
- `NATURAL_LANGUAGE_QUERY`: IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION
- `BOOLEAN_MODE`: IN BOOLEAN MODE
- `QUERY_EXPANSION`: WITH QUERY EXPANSION

The `$searchable` property should contain an array of conditions that you search full-

```
. . . .
use App\Traits\QueryKit;

class User extends Authenticatable
{
    use Notifiable;
    use HasOtpAuth;
    use HasGuardian;
    use QueryKit;

    protected $excludable = ['deleted_at', 'created_at', 'updated_at'];

    protected $searchable = [
        'name', 'address'
    ];

. . . .
}
```

```
    public function search()
    {
        $data = User::searchFulltext('ngo')->exclude()->get()->toArray();
        dump($data);
    }
```

You flexibly add matched columns by `searchableCols()`

```
    public function search()
    {
        $data = User::searchableCols(['name', 'address'])
                        ->searchFulltext('ngo')
                        ->exclude()
                        ->get()
                        ->toArray();
        dump($data);
    }
```

You must create a `full-text index` on the table before you run full-text queries on a table. The full-text index can include one or more character-based columns in the table.

```
ALTER TABLE `users` ADD FULLTEXT(`name`, `address`);
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity54

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

Total

5

Last Release

1758d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8dfc050aef777dd165bc3f60e724e4b53471854fcb3b522c103c936bd56e6643?d=identicon)[ngodinhcuong](/maintainers/ngodinhcuong)

---

Top Contributors

[![cuongnd-nta](https://avatars.githubusercontent.com/u/68364059?v=4)](https://github.com/cuongnd-nta "cuongnd-nta (7 commits)")[![cuongdinhngo](https://avatars.githubusercontent.com/u/55419546?v=4)](https://github.com/cuongdinhngo "cuongdinhngo (1 commits)")

---

Tags

filterfulltext-searchlaravelmodelphpupsertlaravelmodeleloquentqueryupsert

### Embed Badge

![Health badge](/badges/cuongnd88-lara-query-kit/health.svg)

```
[![Health](https://phpackages.com/badges/cuongnd88-lara-query-kit/health.svg)](https://phpackages.com/packages/cuongnd88-lara-query-kit)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[elipzis/laravel-cacheable-model

Automatic query-based model cache for your Laravel app

15546.1k](/packages/elipzis-laravel-cacheable-model)[omalizadeh/laravel-query-filter

A laravel package for resource filtering via request query string

163.0k](/packages/omalizadeh-laravel-query-filter)

PHPackages © 2026

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