Package Data | |
---|---|
Maintainer Username: | AntonioCarlosRibeiro |
Maintainer Contact: | acr@antoniocarlosribeiro.com (Antonio Carlos Ribeiro) |
Package Create Date: | 2017-10-27 |
Package Last Update: | 2024-10-28 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-08 03:04:57 |
Package Statistics | |
---|---|
Total Downloads: | 2,945,031 |
Monthly Downloads: | 33,001 |
Daily Downloads: | 1,567 |
Total Stars: | 94 |
Total Watchers: | 6 |
Total Forks: | 27 |
Total Open Issues: | 1 |
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;
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.
collect(
collect(
collect(
collect(
$collection['cars']
)->unique('constructor')['models']
)->last()['model']
)['colors']
)->first()['rgb']
or
$collection->cars->unique('constructor')->last()->model->colors->first()->rgb
collect($vimeo)->body->data->first()->metadata->connections->likes->total;
Or you prefer this one?
collect($vimeo)['body']['data'][0]['metadata']['connections']['likes']['total'];
{"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')
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']);
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;
Via Composer
$ composer require pragmarx/coollection
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;
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email acr@antoniocarlosribeiro.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.