2017 © Pedro Peláez
 

library eloquent-data-processing

Eloquent ORM support for ViewComponents

image

view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  • Tuesday, February 14, 2017
  • by nayjest
  • Repository
  • 2 Watchers
  • 16 Stars
  • 6,505 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 11 Versions
  • 12 % Grown

The README.md

Logo ViewComponents\EloquentDataProcessing

Release Build Status Scrutinizer Code Quality Code Coverage, (*1)

Eloquent ORM support for ViewComponents, (*2)

Table of Contents

Requirements

  • PHP 5.5+ (hhvm & php7 are supported)

Installation

The recommended way of installing the component is through Composer., (*3)

Run following command:, (*4)

composer require view-components/eloquent-data-processing

Usage

Creating Data Provider

EloquentDataProvider supports 3 types of data sources:, (*5)

  • 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

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:, (*6)

use ViewComponents\ViewComponents\Data\Operation\FilterOperation;

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

Using Illuminate\Database\Eloquent\Builder 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., (*7)

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

It's possible to use EloquentDataProvider if you not deal with Eloquent models., (*8)

use DB;
use ViewComponents\Eloquent\EloquentDataProvider;

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

Data Provider Operations

Eloquent Data provider modifies database query when it has operations., (*9)

Use operations() method for accessing operations collection., (*10)

Documentation related to collections can be found here., (*11)

Example of adding operation:, (*12)

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

Also operations can be specified on data provider creation:, (*13)


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

Data providers implements IteratorAggregate interface, so you can iterate it like array:, (*14)


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:, (*15)


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

Please see Contributing Guidelines and Code of Conduct for details., (*16)

Testing

This package bundled with unit tests (PHPUnit)., (*17)

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

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

Command for running tests:, (*19)

composer test

Security

If you discover any security related issues, please email mail@vitaliy.in instead of using the issue tracker., (*20)

License

© 2015 — 2016 Vitalii Stepanenko, (*21)

Licensed under the MIT License., (*22)

Please see License File for more information., (*23)

The Versions

14/02 2017

dev-master

9999999-dev https://github.com/view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitalii [Nayjest] Stepanenko

laravel laravel4 laravel-4 laravel5 laravel-5

14/02 2017

v1.2.4

1.2.4.0 https://github.com/view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitalii [Nayjest] Stepanenko

laravel laravel4 laravel-4 laravel5 laravel-5

31/08 2016

v1.2.3

1.2.3.0 https://github.com/view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitalii [Nayjest] Stepanenko

laravel laravel4 laravel-4 laravel5 laravel-5

24/06 2016

v1.2.2

1.2.2.0 https://github.com/view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitalii [Nayjest] Stepanenko

laravel laravel4 laravel-4 laravel5 laravel-5

23/06 2016

v1.2.1

1.2.1.0 https://github.com/view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitalii [Nayjest] Stepanenko

laravel laravel4 laravel-4 laravel5 laravel-5

08/04 2016

v1.2.0

1.2.0.0 https://github.com/view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitalii [Nayjest] Stepanenko

laravel laravel4 laravel-4 laravel5 laravel-5

07/04 2016

v1.1.1

1.1.1.0 https://github.com/view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitalii [Nayjest] Stepanenko

laravel laravel4 laravel-4 laravel5 laravel-5

31/03 2016

v1.1.0

1.1.0.0 https://github.com/view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitalii [Nayjest] Stepanenko

laravel laravel4 laravel-4 laravel5 laravel-5

26/02 2016

v1.0.0

1.0.0.0 https://github.com/view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitalii [Nayjest] Stepanenko

laravel laravel4 laravel-4 laravel5 laravel-5

25/02 2016

v1.0.0-beta.2

1.0.0.0-beta2 https://github.com/view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitalii [Nayjest] Stepanenko

laravel laravel4 laravel-4 laravel5 laravel-5

25/02 2016

v1.0.0-beta.1

1.0.0.0-beta1 https://github.com/view-components/eloquent-data-processing

Eloquent ORM support for ViewComponents

  Sources   Download

MIT

The Requires

 

by Vitalii [Nayjest] Stepanenko

laravel laravel4 laravel-4 laravel5 laravel-5