PHPackages                             rcbytes/fetch - 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. rcbytes/fetch

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

rcbytes/fetch
=============

fetch your eloquent models

715PHP

Since Nov 29Pushed 10y ago2 watchersCompare

[ Source](https://github.com/melloc01/fetch)[ Packagist](https://packagist.org/packages/rcbytes/fetch)[ RSS](/packages/rcbytes-fetch/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Fetch
=====

[](#fetch)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Query `Eloquent` models easily. it is ideal for who uses Laravel as an API

Install
-------

[](#install)

Via Composer

```
$ composer require rcbytes/fetch
```

On `config/app.php`

Service Provider:

```
rcbytes\fetch\FetchServiceProvider::class
```

Facade:

```
'Fetch' => rcbytes\fetch\Fetch::class
```

Usage
-----

[](#usage)

#### Controller

[](#controller)

```
...

class UserController extends Controller

	public function index(Request $request)
	{

	    // your criteria will overwrite criteria from Request->where
	    $where = [ "account_id" => $request->user()->account_id ];
  		return Fetch::all(App\User::query(), $where);

	}

	public function show($id)
	{

	    // third parameter $key defaults to "id"
  		return Fetch::one(App\User::query(), $id);

	}

...
```

#### Model:

[](#model)

```
class User implements AuthenticatableContract, CanResetPasswordContract
{
    ...
    public function friends()
    {

    	return $this->hasMany(\App\User::class);

    }

    public function posts()
    {

    	return $this->hasMany(\App\Model\Post::class);

    }
    ...
}
```

#### Request :

[](#request-)

Get all `Users` with their `Posts` and `Friends`

```
GET /user?with=["posts", "friends"]

```

Get `Users` with their `Posts` and `Friends` that `age` equals 30

```
GET /user?with=["posts", "friends"]&where={age: 30}

```

Get `Users` with their `Posts` and their `Comments` and `Friends` that have at least one `Friend` with `age` greater than 30

```
GET /user?with=["posts.comments", "friends"]&where={"friends.age":[ ">", 30]}

```

Get `User` of `key = 1` with their `Posts`, `Friends` and `Friends of Friends`

```
GET /user/1?with=["posts", "friends.friends"]

```

#### Parameters:

[](#parameters)

- array `with`: It expects the `Models` to have the `relationship method`. Accepts `dot notation`, both `Models` come when used. eg.: `?with:["posts.comments"]`. `User::posts` and `Post::comments` methods must exist
- object|mixed `where`: It expects the `Models` to have the queried columns. Accepts `dot notation`, queries the relationship, if found at least one that matches the criteria, it returns the Model. eg.: `?where:{age: 30}`, `?where:{age:[">", 30]}`, `?where:{"friends.age":[">", 30]}`
- integer `take`: takes this number of `Models`
- integer `paginate`: also known as `per page`
- integer `page`: page number

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ to do
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Rafael Mello Campanari](https://github.com/rcbytes)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

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

---

Top Contributors

[![melloc01](https://avatars.githubusercontent.com/u/4994258?v=4)](https://github.com/melloc01 "melloc01 (16 commits)")

### Embed Badge

![Health badge](/badges/rcbytes-fetch/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[yemenopensource/filament-excel

This package useful for importing excel files into models.

194.2k](/packages/yemenopensource-filament-excel)

PHPackages © 2026

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