PHPackages                             volosyuk/simple-eloquent - 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. volosyuk/simple-eloquent

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

volosyuk/simple-eloquent
========================

Adaptation of eloquent for retrieving its attributes

8.0(5y ago)56110.2k—2%10[1 PRs](https://github.com/andreyvolosyuk/simple-eloquent/pulls)MITPHPPHP ^7.2CI failing

Since Nov 16Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/andreyvolosyuk/simple-eloquent)[ Packagist](https://packagist.org/packages/volosyuk/simple-eloquent)[ RSS](/packages/volosyuk-simple-eloquent/feed)WikiDiscussions master Synced 2d ago

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

Simple eloquent extension for Laravel
=====================================

[](#simple-eloquent-extension-for-laravel)

[![Latest Version](https://camo.githubusercontent.com/e3913aa7f0aba393c3f9585f501f73b0624d07cce0ce1c71e7046791b828594d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766f6c6f7379756b2f73696d706c652d656c6f7175656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/volosyuk/simple-eloquent)[![Software License](https://camo.githubusercontent.com/71f8330d741f5fabf7d8e4fdbccf6c1817479c62871f88a5fe72259a0949027c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616e64726579766f6c6f7379756b2f73696d706c652d656c6f7175656e742e7376673f7374796c653d666c61742d737175617265)](https://github.com/andreyvolosyuk/simple-eloquent/blob/master/LICENSE.txt)[![Quality Score](https://camo.githubusercontent.com/c0c01323115572730327846dbcb893d014d0890f99eb09d6116f1deb8f0dcc44/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616e64726579766f6c6f7379756b2f73696d706c652d656c6f7175656e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/andreyvolosyuk/simple-eloquent/)[![Coverage Status](https://camo.githubusercontent.com/19c30bc8ce4323d527ded8ce0125af7fdc2ea406cc1fd1ed6dfe1e3f627401d5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f616e64726579766f6c6f7379756b2f73696d706c652d656c6f7175656e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/andreyvolosyuk/simple-eloquent/code-structure)[![Total Downloads](https://camo.githubusercontent.com/4dce5a9f62d6f715968c2206e626aaa7da77f3ac1177015f2e29719cf6579ee2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766f6c6f7379756b2f73696d706c652d656c6f7175656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/volosyuk/simple-eloquent)

This extension presents some methods for eloquent ORM in order to reduce time and memory consumption. Sometimes application doesn't need all of eloquent overhead. It just requires to retrieve model's attributes with relations and nothing more. In this case this methods might be enough useful for you.

### Extension supports:

[](#extension-supports)

```
- eloquent relations
- illuminate pagination
- PDO::FETCH_OBJ and PDO::FETCH_ASSOC fetch modes

```

### Requirements

[](#requirements)

```
laravel >= 5.3

```

### Installation

[](#installation)

Run

```
composer require --prefer-dist volosyuk/simple-eloquent "*"

```

or add this code line to the `require` section of your `composer.json` file:

```
"volosyuk/simple-eloquent": "*"

```

### Usage

[](#usage)

Just use *SimpleEloquent* trait in your model. If you want to get models with relations attach SimpleEloquent trait to related models as well.

```
use Volosyuk\SimpleEloquent\SimpleEloquent;
class Department extends \Illuminate\Database\Eloquent\Model
{
    use SimpleEloquent;
}
```

Then use *simple()* method in chain of methods calls.

```
$users = User::whereHas('units')->withCount('units')->with('units')->limit(10)->simple()->get();
$activeUser = User::simple()->where('is_active', 1)->first();
```

### Profit

[](#profit)

##### Example 1 - users with details; 50 per page

[](#example-1---users-with-details-50-per-page)

```
$users = User::with([
    'units.leaders.performance',
    'teams.leaders.performance',
    'programs.courses'
])->limit(50)->get()
```

TimeMemory consumptionget()0.62s6.0mbsimple()-&gt;get()0.19s3.0mb##### Example 2 - select models with 5-level relation

[](#example-2---select-models-with-5-level-relation)

```
$goals = Goal::with('goalUser.user.courses.points.user')->limit(20)->get()
```

TimeMemory consumptionget()1.48s28.5mbsimple()-&gt;get()0.47s15.5mb##### Example 3 - let's select 1000 models

[](#example-3---lets-select-1000-models)

```
$performance = Performance::whereHas('user')->with('goal.goalUser')->limit(1000)->get()
```

TimeMemory consumptionget()0.22s2.0mbsimple()-&gt;get()0.06s1.1mb### What do you lose?

[](#what-do-you-lose)

Since this extension provides less expensive methods you'll definitely lose some functionality. Basic methods return collection of eloquent models in contrast to new functionality which returns collection of stdClasses|arrays. This example will show the difference between results.

```
$categories = Category::with('articles')->get() // want to grab all categories with articles
```

##### *get()* returns

[](#get-returns)

```
Illuminate\Database\Eloquent\Collection::__set_state([
    'items' => [
        0 => Category::__set_state([
            'guarded' => [],
            'connection' => 'default',
            'table' => NULL,
            'primaryKey' => 'id',
            'keyType' => 'int',
            'incrementing' => true,
            'with' => [],
            'withCount' => [],
            'perPage' => 15,
            'exists' => true,
            'wasRecentlyCreated' => false,
            'attributes' => [
                'id' => '1',
                'name' => 'Test category',
                'created_at' => '2017-12-21 12:33:34',
                'updated_at' => '2017-12-21 12:33:34'
            ],
            'original' => [
                'id' => '1',
                'name' => 'Test category',
                'created_at' => '2017-12-21 12:33:34',
                'updated_at' => '2017-12-21 12:33:34',
            ],
            'changes' => [],
            'casts' => [],
            'dates' => [],
            'dateFormat' => NULL,
            'appends' => [],
            'dispatchesEvents' => [],
            'observables' => [],
            'relations' => [
                'articles' => Illuminate\Database\Eloquent\Collection::__set_state([
                    'items' => [
                        0 => Article::__set_state([
                            'guarded' => [],
                            'connection' => 'default',
                            'table' => NULL,
                            'primaryKey' => 'id',
                            'keyType' => 'int',
                            'incrementing' => true,
                            'with' => [],
                            'withCount' => [],
                            'perPage' => 15,
                            'exists' => true,
                            'wasRecentlyCreated' => false,
                            'attributes' => [
                                'id' => '1',
                                'category_id' => '1',
                                'title' => 'Test article',
                                'created_at' => '2017-12-21 12:33:34',
                                'updated_at' => '2017-12-21 12:33:34',
                            ],
                            'original' => [
                                'id' => '1',
                                'category_id' => '1',
                                'title' => 'Test article',
                                'created_at' => '2017-12-21 12:33:34',
                                'updated_at' => '2017-12-21 12:33:34',
                            ],
                            'changes' => [],
                            'casts' => [],
                            'dates' => [],
                            'dateFormat' => NULL,
                            'appends' => [],
                            'dispatchesEvents' => [],
                            'observables' => [],
                            'relations' => [],
                            'touches' => [],
                            'timestamps' => true,
                            'hidden' => [],
                            'visible' => [],
                            'fillable' => [],
                        ]),
                    ],
                ]),
            ],
            'touches' => [],
            'timestamps' => true,
            'hidden' => [],
            'visible' => [],
            'fillable' => [],
        ])
    ]
]);
```

##### *simple()-&gt;get()* returns

[](#simple-get-returns)

```
Illuminate\Support\Collection::__set_state([
    'items' => [
        0 => stdClass::__set_state([
            'id' => '1',
            'name' => 'Test category',
            'created_at' => '2017-12-21 12:43:44',
            'updated_at' => '2017-12-21 12:43:44',
            'articles' => Illuminate\Support\Collection::__set_state([
                'items' => [
                    0 => stdClass::__set_state([
                        'id' => '1',
                        'category_id' => '1',
                        'title' => 'Test article',
                        'created_at' => '2017-12-21 12:43:44',
                        'updated_at' => '2017-12-21 12:43:44',
                    ]),
                ],
            ]),
        ]),
    ]
]);
```

Since you'll get stdClasses|arrays you won't reach out to casting, appends, guarded/fillable, crud and another possibilities. That's why new methods are much faster 😏

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance55

Moderate activity, may be stable

Popularity45

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 81.8% 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 ~52 days

Recently: every ~196 days

Total

26

Last Release

1837d ago

Major Versions

5.8.0 → 6.0.02019-11-05

6.0.1 → 7.02021-06-22

7.0 → 8.02021-06-22

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7975788?v=4)[Andrei Valasiuk](/maintainers/andreyvolosyuk)[@andreyvolosyuk](https://github.com/andreyvolosyuk)

---

Top Contributors

[![andreyvolosyuk](https://avatars.githubusercontent.com/u/7975788?v=4)](https://github.com/andreyvolosyuk "andreyvolosyuk (36 commits)")[![jsperrer](https://avatars.githubusercontent.com/u/129270249?v=4)](https://github.com/jsperrer "jsperrer (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![antonkomarev](https://avatars.githubusercontent.com/u/1849174?v=4)](https://github.com/antonkomarev "antonkomarev (1 commits)")[![kevinpijning](https://avatars.githubusercontent.com/u/2886081?v=4)](https://github.com/kevinpijning "kevinpijning (1 commits)")[![sineld](https://avatars.githubusercontent.com/u/445349?v=4)](https://github.com/sineld "sineld (1 commits)")[![jonathan-dij](https://avatars.githubusercontent.com/u/102718572?v=4)](https://github.com/jonathan-dij "jonathan-dij (1 commits)")

---

Tags

eloquentlaravelperformance-optimizationlaraveleloquent

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/volosyuk-simple-eloquent/health.svg)

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

###  Alternatives

[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M146](/packages/laravel-cashier)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)

PHPackages © 2026

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