PHPackages                             xabou/query - 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. xabou/query

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

xabou/query
===========

Laravel 5 Query Object

v0.7.0(6y ago)11051[1 PRs](https://github.com/xabou/query/pulls)MITPHP

Since Oct 14Pushed 5y ago1 watchersCompare

[ Source](https://github.com/xabou/query)[ Packagist](https://packagist.org/packages/xabou/query)[ RSS](/packages/xabou-query/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (1)Versions (6)Used By (0)

Abandoned
=========

[](#abandoned)

All good things come to an end. Thanks everyone for using this package :)

Laravel Query
=============

[](#laravel-query)

Query is a package that provides queries objects for your Laravel application.

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

[](#installation)

### 1: Require via composer

[](#1-require-via-composer)

From the command line, run:

```
composer require xabou/query

```

Alternatively, you can put the following in your composer.json file:

```
{
    "require": {
        "xabou/query": "^0.5.0"
    }
}

```

### 2: Register Service Provider

[](#2-register-service-provider)

Open `config/app.php` and append `providers` array with:

```
Xabou\Query\QueryServiceProvider::class

```

Usage
-----

[](#usage)

### Create A Query

[](#create-a-query)

With the package now installed, a new artisan command is available.

```
php artisan make:query PopularUsersQuery

```

A 'Queries' directory will be created, if it doesn't already exist, within your app.

### Declare Query Body

[](#declare-query-body)

Within the body method you can declare your query:

```
public static function body()
{
    return User::select(['user.username', 'user.id', 'user.verified', 'popularity_user.score'])
                 ->join('popularity_user', 'users.id', '=', 'popularity_user.user_id')
                 ->where('user.verified', 1)
                 ->with('avatar')
                 ->orderBy('popularity_user.score', 'DESC')
                 ->orderBy('user.username', 'ASC');
}
```

### Fetching Results

[](#fetching-results)

#### Body

[](#body)

This is where your query logic should be declared. This method returns an instance of Eloquent Database Builder or executed query.

#### Get

[](#get)

This is a wrapper for body method. When body returns an instance of Eloquent Database Builder this method delegates to Builder's get method.

#### 1: Delegate to Eloquent Database Builder

[](#1-delegate-to-eloquent-database-builder)

You can call any method defined in Eloquent Database Builder by returning an instance of it, like above example.

```
// Dynamic static method calls
PopularUsersQuery::first()

// or
PopularUsersQuery::get()

// Dynamic method calls
(new PopularUsersQuery())->get()
```

#### 2: Execute query

[](#2-execute-query)

Within the body method you can also execute your query.

```
public static function body()
{
    return User::select(['user.username', 'user.id', 'user.verified', 'popularity_user.score'])
                 ->join('popularity_user', 'users.id', '=', 'popularity_user.user_id')
                 ->where('user.verified', 1)
                 ->with('avatar')
                 ->orderBy('popularity_user.score', 'DESC')
                 ->paginate();
}
```

Then simply call body or get method on Query.

```
PopularUsersQuery::body()

//or

PopularUsersQuery::get()
```

**Note:** In this case get method serves as an alias to body method. It won't delegate to Eloquent Database Builder.

#### 3: Chain query

[](#3-chain-query)

By returning the content of body you can continue chaining methods on Eloquent Database Builder.

```
PopularUsersQuery::body()->where('age', '>', 25)->get();
```

### Passing Arguments

[](#passing-arguments)

You can pass as many arguments as you want through body or get methods.

```
$age = 25;
$verified = 1
PopularUsersQuery::get($age, $verified);

public static function body($age, $verified)
{
    return User::where('age', '>', $age)
                 ->where('verified', $verified);
}
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

4

Last Release

2316d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f2a22b6562ff3839f7a32ca3f75dea09ad70731a0d71cdd9e2e48c2616de340?d=identicon)[xabou](/maintainers/xabou)

---

Top Contributors

[![dweingart](https://avatars.githubusercontent.com/u/3514416?v=4)](https://github.com/dweingart "dweingart (1 commits)")[![dweingart-iol](https://avatars.githubusercontent.com/u/262418353?v=4)](https://github.com/dweingart-iol "dweingart-iol (1 commits)")[![xabou](https://avatars.githubusercontent.com/u/13403132?v=4)](https://github.com/xabou "xabou (1 commits)")

---

Tags

laravelquery

### Embed Badge

![Health badge](/badges/xabou-query/health.svg)

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

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[rennokki/laravel-eloquent-query-cache

Adding cache on your Laravel Eloquent queries' results is now a breeze.

1.1k4.0M14](/packages/rennokki-laravel-eloquent-query-cache)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[tpetry/laravel-query-expressions

Database-independent Query Expressions as a replacement to DB::raw calls

357436.5k2](/packages/tpetry-laravel-query-expressions)

PHPackages © 2026

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