2017 © Pedro Peláez
 

library coollection

Laravel Illuminate collection with objectified properties

image

pragmarx/coollection

Laravel Illuminate collection with objectified properties

  • Monday, February 19, 2018
  • by AntonioCarlosRibeiro
  • Repository
  • 2 Watchers
  • 44 Stars
  • 29,217 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 21 Versions
  • 69 % Grown

The README.md

Coollection

Latest Stable Version License Code Quality Build Downloads , (*1)

Coverage StyleCI PHP , (*2)

Access collection items as objects properties

Coollection is Laravel's Illuminate\Collection repackaged to be used as all properties were objects:, (*3)

``` php $collection->name, (*4)

$collection->addresses->first()->street_name, (*5)

$collection->flatten()->cars->filter(function($car) { return $car->name == 'ferrari' })->last()->model, (*6)

$countries->where('name.common', 'United States')->first()->currency->name->english;, (*7)


#### Tightenco\Collect To be agnostic and have complete idependence from Laravel's, but also to allow it to be used in Laravel applications, this package extends [Tightenco\Collect](https://github.com/tightenco/collect), developed by [Matt Stauffer](https://twitter.com/stauffermatt) from [Tighten](https://twitter.com/tightenco). ## Why? #### Answering with a question: which one is easier to look at? ``` php collect( collect( collect( collect( $collection['cars'] )->unique('constructor')['models'] )->last()['model'] )['colors'] )->first()['rgb']

or, (*8)

``` php $collection->cars->unique('constructor')->last()->model->colors->first()->rgb, (*9)


#### Isn't this easier on the eyes? ``` php collect($vimeo)->body->data->first()->metadata->connections->likes->total;

Or you prefer this one?, (*10)

``` php collect($vimeo)['body']['data'][0]['metadata']['connections']['likes']['total'];, (*11)


#### Used with Laravel request it is useful, if you receive: ``` json {"pagination":{"perPage":100,"pageNumber":1}}

You collect() it:, (*12)

``` php $input = coollect($request->all());, (*13)


And you can just: ``` php $input->pagination->perPage

Instead of:, (*14)

``` php $input->get('pagination')['perPage'], (*15)


You can also use "dot notation" to get your items: ``` php $input->get('pagination.perPage')

PHP Agnostic

This is an agnostic PHP package, an extraction of Illuminate\Support\Collection with all needed classes, interfaces and traits. For that if you wish just to use Illuminate's Collection, you just have to import the class Collection:, (*16)

``` php $collection = new IlluminateExtracted\Support\Collection(['my collection']);, (*17)


or use the usual helper: ``` php $collection = collect(['my collection']);

Documentation

It's Laravel's Collection, at full power, so you can check its docs. The only difference is that you can access items (array keys) as properties, like any other PHP object:, (*18)

``` php $collection->map($mapper)->reduce($reducer)->random()->address->street, (*19)

$this->sendThanks( $collection->where('full_name', 'Barack Obama')->addresses->random() );, (*20)

$countries->where('name.common', 'United States')->first()->currency->symbol;, (*21)


## Install Via Composer ``` bash $ composer require pragmarx/coollection

Usage

Instantiate, the class directly or using the helper:, (*22)

``` php $c = new Coollection(['first_name' => 'Barack Obama']);, (*23)

$c = coollect(['first_name' => 'Barack Obama']);, (*24)


Then you use it as an object: ``` php echo $c->first_name; // Barack Obama echo $c->flip()->barak_obama == 'first_name' ? 'true' : 'false'; // true

One word keys are case insensitive:, (*25)

``` php echo $c->rio; echo $c->RIO;, (*26)


## Change log Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. ## Testing ``` bash $ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details., (*27)

Security

If you discover any security related issues, please email acr@antoniocarlosribeiro.com instead of using the issue tracker., (*28)

Credits

License

The MIT License (MIT). Please see License File for more information., (*29)

The Versions

18/02 2018
13/02 2018
13/02 2018
31/01 2018

v0.5.0

0.5.0.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel collection pragmarx

20/01 2018

v0.2.0

0.2.0.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel collection pragmarx

14/01 2018

v0.1.9

0.1.9.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel collection pragmarx

18/12 2017

v0.1.8

0.1.8.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel collection pragmarx

12/12 2017

v0.1.7

0.1.7.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel collection pragmarx

07/12 2017

v0.1.6

0.1.6.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

laravel collection pragmarx

01/12 2017

v0.1.5

0.1.5.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

laravel collection pragmarx

11/11 2017

v0.1.4

0.1.4.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

laravel collection pragmarx

10/11 2017

v0.1.3

0.1.3.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

laravel collection pragmarx

29/10 2017

v0.1.2

0.1.2.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

laravel collection pragmarx

29/10 2017

v0.1.1

0.1.1.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

laravel collection pragmarx

29/10 2017

v0.1.0

0.1.0.0 https://github.com/antonioribeiro/coollection

Laravel Illuminate collection with objectified properties

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

laravel collection pragmarx