Download the PHP package pion/laravel-support-collection without Composer

On this page you can find all versions of the php package pion/laravel-support-collection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-support-collection

Laravel Collection support package

A mix of classes for improving the Collection.

Installation

composer require pion/laravel-support-collection

NestedObjectCollection

Creates a nested collection from flat collection to child nested collection based on parent property and id property.

It's expected that the values are objects, it will insert the childs into the desired property.

All childs are stored to childs property in the object. Can be empty.

You can call all Collection methods on the NestedObjectCollection object, all method calls are passed into the collection

Construct

Groups the items by the parent property and loops from the top of tree (null property or different value) and adds childs to the object.

Parameters

Eloquent usage

It's advised to set a property in the Eloquent model to prevent creating childs into the attributes. For default property name you can use the ChildsCollectionTrait. This provides a public $childs property for your Eloquent model

Example

$object1 = new stdClass();
$object1->id = 1;

// this is the root!
$object1->parent_id = null;

$object2 = new stdClass();

$object2->id = 2;
$object2->parent_id = 2;

$object3 = new stdClass();

$object3->id = 3;
$object3->parent_id = 1;

$example = new \Pion\Support\Collection\NestedObjectCollection(new \Illuminate\Support\Collection([
    $object1, $object2, $object3
]));

$collection = $example->getCollection();

This example will create a collection of single item (the $object1). This objects will have a new property $childs which is holding a Collection of single item $object2 that holds again property $childs with a single item $object3

GroupedCollection

Enables a quick how to build a grouped collection. Just add a new item to the collection with given group key and the value. Optionally you can provide also the key for the value.

public function add($groupKey, $value, $key = null)

Example

The use of the collection is same as standard collection.

$groupedCollection = new GroupedCollection();
$groupedCollection->add("1", "test 1");
$groupedCollection->add("1", "test 2");
$groupedCollection->add("1", "test 3");
$groupedCollection->add("2", "test 2-1");
$groupedCollection->add("2", "test 2-2");

This will result in a collection of items with a collection object. If you export the collection into array you will grouped array as expected.

var_dump($groupedCollection->toArray());

array(2) {
  [1] =>
  array(3) {
    [0] =>
    string(6) "test 1"
    [1] =>
    string(6) "test 2"
    [2] =>
    string(6) "test 3"
  }
  [2] =>
  array(2) {
    [0] =>
    string(8) "test 2-1"
    [1] =>
    string(8) "test 2-2"
  }
}

All versions of laravel-support-collection with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ^6 || ^7 || ^8 || ^9
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pion/laravel-support-collection contains the following files

Loading the files please wait ....