GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - diamonddevgroup/coollection: Laravel Collection Objectified

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

147 Commits
147 Commits

Folders and files

NameName
Last commit message
Last commit date
src/package
src/package
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.scrutinizer.yml
.scrutinizer.yml
 
 
.styleci.yml
.styleci.yml
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
ISSUE_TEMPLATE.md
ISSUE_TEMPLATE.md
 
 
LICENSE.md
LICENSE.md
 
 
PULL_REQUEST_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
composer.lock
composer.lock
 
 
phpunit.xml
phpunit.xml
 
 

Repository files navigation

Coollection

Latest Stable Version License Code Quality Build Downloads

Coverage StyleCI PHP

Access collection items as objects properties

Coollection is Laravel's Illuminate\Collection repackaged to be used as all properties were objects:

$collection->name

$collection->addresses->first()->street_name

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

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

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, developed by Matt Stauffer from Tighten.

Why?

Answering with a question: which one is easier to look at?

collect(
    collect(
        collect(
            collect(
                $collection['cars']
            )->unique('constructor')['models']
        )->last()['model']
    )['colors']
)->first()['rgb']

or

$collection->cars->unique('constructor')->last()->model->colors->first()->rgb

Isn't this easier on the eyes?

collect($vimeo)->body->data->first()->metadata->connections->likes->total;

Or you prefer this one?

collect($vimeo)['body']['data'][0]['metadata']['connections']['likes']['total'];

Used with Laravel request it is useful, if you receive:

{"pagination":{"perPage":100,"pageNumber":1}}

You collect() it:

$input = coollect($request->all());

And you can just:

$input->pagination->perPage

Instead of:

$input->get('pagination')['perPage']

You can also use "dot notation" to get your items:

$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:

$collection = new IlluminateExtracted\Support\Collection(['my collection']); 

or use the usual helper:

$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:

$collection->map($mapper)->reduce($reducer)->random()->address->street

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

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

Install

Via Composer

$ composer require pragmarx/coollection

Usage

Instantiate, the class directly or using the helper:

$c = new Coollection(['first_name' => 'Barack Obama']);

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

Then you use it as an object:

echo $c->first_name;

// Barack Obama


echo $c->flip()->barak_obama == 'first_name' 
    ? 'true' 
    : 'false';

// true

One word keys are case insensitive:

echo $c->rio;
echo $c->RIO;

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

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

Credits

  • This package is an extension of Tightenco\Collect, developed by Matt Stauffer from Tighten.
  • Tightenco\Collect is an extraction of The Laravel Framework's Collection, created by Taylor Otwell.
  • Package creator Antonio Carlos Ribeiro
  • Contributors

License

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

About

Laravel Collection Objectified

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.