PHPackages                             kobykorman/eloquentify - 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. kobykorman/eloquentify

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

kobykorman/eloquentify
======================

Easily transform complex custom query results into fully hydrated hierarchical Eloquent models.

v1.0.0(10mo ago)152MITPHPPHP &gt;=8.0

Since Jul 4Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/kobykorman/eloquentify)[ Packagist](https://packagist.org/packages/kobykorman/eloquentify)[ Docs](https://github.com/kobykorman/eloquentify)[ RSS](/packages/kobykorman-eloquentify/feed)WikiDiscussions master Synced 1mo ago

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

 [![Eloquentify Logo](./assets/logo.png)](./assets/logo.png)

Eloquentify for Laravel
-----------------------

[](#eloquentify-for-laravel)

👎 Lazy Loading (N+1 queries)

😑 Eager Loading (R+1 queries)

😎 Greedy Loading (1 query)

Why Eloquentify?
----------------

[](#why-eloquentify)

### ⚡ Single Query: Replace N+1/R+1 queries with one efficient query

[](#-single-query-replace-n1r1-queries-with-one-efficient-query)

### 💯 Eloquent Models: Get real Eloquent models, not plain objects

[](#-eloquent-models-get-real-eloquent-models-not-plain-objects)

### 🔗 Nested Relations: Support for complex hierarchies of any depth

[](#-nested-relations-support-for-complex-hierarchies-of-any-depth)

### ✨ Clean API: Maintain Laravel's elegant syntax

[](#-clean-api-maintain-laravels-elegant-syntax)

Using Eloquent can be costly in terms of how many queries are fired behind the scenes when a model has many relationships. What if we could leverage the database for what it was meant for while retaining the Eloquent experience?

Eloquentify easily transforms the result of a single custom query into nested Eloquent models, so you can continue enjoying the Eloquent API and all of its benefits.

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

[](#installation)

```
composer require kobykorman/eloquentify
```

Quick Start
-----------

[](#quick-start)

### 1. Add the trait:

[](#1-add-the-trait)

```
// App\Models\Model
use Illuminate\Database\Eloquent\Model as BaseModel;

class Model extends BaseModel
{
    use EloquentifiesQueries;
}
```

### 2. Write the query:

[](#2-write-the-query)

```
// App\Models\User
class User extends Model
{
    public static function getById($id)
    {
        // 1 custom query
        $result = DB::table('users')
        ->select('...')
        ->join('person...')
        ->join('team...')
        // ...
        ->where('id', $id)
        ->get()
```

### 3. Transform the result:

[](#3-transform-the-result)

```

        // feed the result and the relations hierarchy
        // and get them all properly hydrated and nested
        return User::eloquentify($result, [
            Person::class
            Team::class,
            Role::nest(Permission::nest(
                Resource::class,
                Ability::class
            ))
            Post::nest(Comment::class)
        ])
    }
}
```

### 4. Enjoy:

[](#4-enjoy)

```
// App\Controllers\UserController
$userName = User::getById(1)->person->name
```

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- Laravel 9.0 or higher

### Models:

[](#models)

- Must follow Laravel naming conventions (e.g. `User`, `Post`, `UserProfile` - not `user`, `Posts`, `user_profile`)
- Must be instantiatable without parameters (e.g. `new User()`, `new Post()` - not `new User($data)`)
- All relation methods must exist on the model (e.g. `User` model must have `posts()` method)
    - Relation method names must match either:
        - Singular method names are assumed to be "one" (e.g. `profile()`, `author()`, `category()`)
        - Plural method names are assumed to be "many" (e.g. `posts()`, `comments()`, `tags()`)

### Query:

[](#query)

- Must include all related models' primary keys and the columns for the desired attributes
- Related model columns must be snake\_cased prefixed, e.g.: ```
    (SELECT users.id, users.name, posts.id AS post_id, posts.title AS post_title)
    ```
- Results must be provided as a Laravel Collection (`DB::table()...->get()`)

License
-------

[](#license)

This library is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance54

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community7

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

318d ago

### Community

Maintainers

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

---

Top Contributors

[![kobykorman](https://avatars.githubusercontent.com/u/5124919?v=4)](https://github.com/kobykorman "kobykorman (6 commits)")

---

Tags

laraveldatabaseperformanceormeloquentoptimization

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/kobykorman-eloquentify/health.svg)

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

###  Alternatives

[sarfraznawaz2005/indexer

Laravel package to monitor SELECT queries and offer best possible INDEX fields.

562.7k](/packages/sarfraznawaz2005-indexer)[ymigval/laravel-model-cache

Laravel package for caching Eloquent model queries

7642.2k3](/packages/ymigval-laravel-model-cache)[msafadi/laravel-eloquent-join-with

Laravel Eloquent Join With Relationships

1646.0k](/packages/msafadi-laravel-eloquent-join-with)[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)[andreagroferreira/laravel-sync-tracker

A Laravel package for tracking entity synchronization status between systems

113.0k](/packages/andreagroferreira-laravel-sync-tracker)

PHPackages © 2026

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