PHPackages                             view-components/eloquent-data-processing - 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. view-components/eloquent-data-processing

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

view-components/eloquent-data-processing
========================================

Eloquent ORM support for ViewComponents

v1.2.7(4y ago)1885.8k↓17.3%2[1 issues](https://github.com/view-components/eloquent-data-processing/issues)2MITPHPPHP ^5.5||^7||^8

Since Feb 25Pushed 4y ago1 watchersCompare

[ Source](https://github.com/view-components/eloquent-data-processing)[ Packagist](https://packagist.org/packages/view-components/eloquent-data-processing)[ Docs](https://github.com/view-components/eloquent-data-processing)[ RSS](/packages/view-components-eloquent-data-processing/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (14)Used By (2)

[![Logo](https://raw.githubusercontent.com/view-components/logo/master/view-components-logo-without-text-42.png)](https://raw.githubusercontent.com/view-components/logo/master/view-components-logo-without-text-42.png) ViewComponents\\EloquentDataProcessing
================================================================================================================================================================================================================================================================

[](#-viewcomponentseloquentdataprocessing)

[![Release](https://camo.githubusercontent.com/1146bd808502f9cd0bab4edbb9d8ee3813c608e7d8d638e2d0b2a21d713fc7e1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766965772d636f6d706f6e656e74732f656c6f7175656e742d646174612d70726f63657373696e672e737667)](https://packagist.org/packages/view-components/eloquent-data-processing)[![Build Status](https://camo.githubusercontent.com/3fc848d4896ba20be2b1aa62261018a59f1c3a4b08d7928f06346ddd89ddf5ff/68747470733a2f2f7472617669732d63692e6f72672f766965772d636f6d706f6e656e74732f656c6f7175656e742d646174612d70726f63657373696e672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/view-components/eloquent-data-processing)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5639450ab49274e2b9bbd2ad028f0a7bce1c65a77413f6f3814b96eca8e08c01/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f766965772d636f6d706f6e656e74732f656c6f7175656e742d646174612d70726f63657373696e672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/view-components/eloquent-data-processing/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/c0e1c89cffb28057f863ace263531191a31456a81926c489c82719ec4b593860/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f766965772d636f6d706f6e656e74732f656c6f7175656e742d646174612d70726f63657373696e672f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/view-components/eloquent-data-processing/?branch=master)

Eloquent ORM support for ViewComponents

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)
- [Testing](#testing)
- [Security](#security)
- [License](#license)

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

[](#requirements)

- PHP 5.5+ (hhvm &amp; php7 are supported)

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

[](#installation)

The recommended way of installing the component is through [Composer](https://getcomposer.org).

Run following command:

```
composer require view-components/eloquent-data-processing
```

Usage
-----

[](#usage)

### Creating Data Provider

[](#creating-data-provider)

EloquentDataProvider supports 3 types of data sources:

- Illuminate\\Database\\Eloquent\\Builder instance (database query builder created from model)
- Illuminate\\Database\\Query\\Builder instance (standard database query builder, don't know about models)
- Class name of Eloquent model

#### Using Class Name of Eloquent Model as Data Source

[](#using-class-name-of-eloquent-model-as-data-source)

```
use MyApp\UserModel;
use ViewComponents\Eloquent\EloquentDataProvider;
$provider = new EloquentDataProvider(UserModel::class);
```

If you use class name of Eloquent model as data source, the only way to modify database query is specifying data provider operations:

```
use ViewComponents\ViewComponents\Data\Operation\FilterOperation;

$provider->operations()->add(
    new FilterOperation('role', FilterOperation::OPERATOR_EQ, 'Manager')
);
```

#### Using Illuminate\\Database\\Eloquent\\Builder as Data Source

[](#using-illuminatedatabaseeloquentbuilder-as-data-source)

```
use ViewComponents\Eloquent\EloquentDataProvider;

$provider = new EloquentDataProvider((new MyApp\UserModel)->newQuery());
```

It's possible to specify query parts before creating EloquentDataProvider but note that some parts of query may be changed by data provider operations.

```
use ViewComponents\Eloquent\EloquentDataProvider;

$query = MyApp\UserModel
            ::where('role', '=', 'Manager')
            ->where('company', '=', 'Facebook')
            ->orderBy('id');

$provider = new EloquentDataProvider($query);
```

#### Using Illuminate\\Database\\Query\\Builder as Data Source

[](#using-illuminatedatabasequerybuilder-as-data-source)

It's possible to use EloquentDataProvider if you not deal with Eloquent models.

```
use DB;
use ViewComponents\Eloquent\EloquentDataProvider;

$provider = new EloquentDataProvider(
    DB::table('users')->where('name', '=', 'David')
);
```

### Data Provider Operations

[](#data-provider-operations)

Eloquent Data provider modifies database query when it has operations.

Use operations() method for accessing operations collection.

Documentation related to collections can be found [here](https://github.com/Nayjest/Collection).

Example of adding operation:

```
$provider
    ->operations()
    ->add(new SortOperation('id', SortOperation::ASC));
```

Also operations can be specified on data provider creation:

```
use MyApp\UserModel;
use ViewComponents\Eloquent\EloquentDataProvider;
use ViewComponents\ViewComponents\Data\Operation\FilterOperation;

$provider = new EloquentDataProvider(
    UserModel::class
    [
        new FilterOperation('role', FilterOperation::OPERATOR_EQ, 'Manager')
        new SortOperation('id', SortOperation::DESC),
    ]
);
```

### Extracting data

[](#extracting-data)

Data providers implements IteratorAggregate interface, so you can iterate it like array:

```
use MyApp\UserModel;
use ViewComponents\Eloquent\EloquentDataProvider;

$provider = new EloquentDataProvider(UserModel::class);
foreach ($provider as $user) {
   var_dump($user); // instance of UserModel
}
```

Data provider executes DB query when getIterator() method is called or when iteration begins in case if data is not loaded yet, i. e. calling getIterator() twice will not produce 2 database queries. But changing operations collection will cause resetting cache:

```
use MyApp\UserModel;
use ViewComponents\Eloquent\EloquentDataProvider;
use ViewComponents\ViewComponents\Data\Operation\FilterOperation;

$provider = new EloquentDataProvider(UserModel::class);
// databse query will be executed
$provider->getIterator();

// databse query will not be executed again, iterating over same data
$provider->getIterator();

$provider->operations->add(
  new FilterOperation('id', FilterOperation::OPERATOR_LTE, 5)
)
// databse query will be executed again
$provider->getIterator();
```

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

[](#contributing)

Please see [Contributing Guidelines](contributing.md) and [Code of Conduct](code_of_conduct.md) for details.

Testing
-------

[](#testing)

This package bundled with unit tests (PHPUnit).

To run tests locally, you must install this package as stand-alone project with dev-dependencies:

```
composer create-project view-components/eloquent-data-processing
```

Command for running tests:

```
composer test
```

Security
--------

[](#security)

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

License
-------

[](#license)

© 2015 — 2016 Vitalii Stepanenko

Licensed under the MIT License.

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

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 97.3% 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 ~163 days

Recently: every ~442 days

Total

13

Last Release

1777d ago

PHP version history (2 changes)v1.1.0PHP ^5.5||^7

v1.2.7PHP ^5.5||^7||^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/f774898eb3341eff33d07e1b05bccfb69d084831b7ac151d3079e322d0ff6155?d=identicon)[nayjest](/maintainers/nayjest)

---

Top Contributors

[![Nayjest](https://avatars.githubusercontent.com/u/153999?v=4)](https://github.com/Nayjest "Nayjest (36 commits)")[![hexusdev](https://avatars.githubusercontent.com/u/8880373?v=4)](https://github.com/hexusdev "hexusdev (1 commits)")

---

Tags

laravellaravel 5laravel5Laravel 4laravel4

### Embed Badge

![Health badge](/badges/view-components-eloquent-data-processing/health.svg)

```
[![Health](https://phpackages.com/badges/view-components-eloquent-data-processing/health.svg)](https://phpackages.com/packages/view-components-eloquent-data-processing)
```

###  Alternatives

[baum/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

2.3k1.6M55](/packages/baum-baum)[rutorika/sortable

Adds sortable behavior and ordering to Laravel Eloquent models. Grouping and many to many supported.

299992.5k14](/packages/rutorika-sortable)

PHPackages © 2026

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