PHPackages                             ferrisbane/eloquent-companion - 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. [Caching](/categories/caching)
4. /
5. ferrisbane/eloquent-companion

ActiveLibrary[Caching](/categories/caching)

ferrisbane/eloquent-companion
=============================

A quintessential package containing companion helper functions to extend the usefulness of Laravel's Eloquent ORM

v0.0.1(6y ago)061MITPHPPHP &gt;=5.4.0

Since Aug 28Pushed 6y ago1 watchersCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Eloquent Companion
==================

[](#eloquent-companion)

A quintessential package containing companion helper functions to extend the usefulness of Laravel's Eloquent ORM

- [Installation](#installation)
- [Usage](#usage)

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

[](#installation)

To install through composer you can either use `composer require ferrisbane/eloquent-companion` (while inside your project folder) or include the package in your `composer.json`.

```
"ferrisbane/eloquent-companion": "0.1.*"
```

Then run either `composer install` or `composer update` to download the package.

To use the package with Laravel 5 add the service provider to the list of service providers in `config/app.php`.

```
'providers' => [
    ...

    Ferrisbane\EloquentCompanion\Laravel5ServiceProvider::class

    ...
];
```

Usage
-----

[](#usage)

Once the service provider has been added to your projects provider list the companion helpers are ready to use.

### withWhereHas

[](#withwherehas)

The withWhereHas helper is useful if you wish to run a `->whereHas()` query on your model and also want to eager load the same relationship without writing the same query in the `->with()` function. Using `->withWhereHas()` keeps your code clean and DRY!

For example if you have a user model and want to return only users that have paid order AND also eager load the paid orders:

```
User::where('active', true)
    ->withWhereHas('orders', function($query) {
        $query->where('paid', true);
    })
    ->get();
```

As a comparison in standard Eloquent you would have to write the query out twice, which can become messy for larger queries and changes to one query will have to be replicated again:

```
User::where('active', true)
    ->whereHas('orders', function($query) {
        $query->where('paid', true);
    })
    ->with([
        'orders' => function($query) {
            $query->where('paid', true);
        }
    ])
    ->get();
```

### toQuery

[](#toquery)

When writing Eloquent queries it can be useful to see what SQL query it will run. Eloquent provides the `->toSql()` function to help you with that, however any bindings wont be populated in the output. The `->toQuery()` function is here to help!

```
User::where('email', 'john@example.com')
    ->toQuery();
```

Taking a look at the above query the standard `->toSql()` function would return: `SELECT * FROM users WHERE email = ?`. We cant just copy and paste that output into our favorite database client.

However with the `->toQuery()` function we can, as it will output: `SELECT * FROM users where email = 'john@example.com'`. This is extremely useful when debugging those big queries that can contain 10+ bindings.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

2449d ago

### Community

Maintainers

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

---

Tags

phplaravelpackagecache

### Embed Badge

![Health badge](/badges/ferrisbane-eloquent-companion/health.svg)

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

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[swayok/alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea. Powered by cache pool implementations provided by http://www.php-cache.com/

202541.1k6](/packages/swayok-alternative-laravel-cache)[antennaio/laravel-clyde

Image uploads and manipulation for Laravel, a wrapper around Glide

292.6k](/packages/antennaio-laravel-clyde)

PHPackages © 2026

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