chrgriffin/collection-macro-thanos

Laravel Collection macro: randomly delete half of the items in a Collection.

v1.0.0 2020-02-28 21:52 UTC

This package is auto-updated.

Last update: 2024-05-29 04:29:02 UTC


README

Build Status Coverage Status

Laravel Collection Macro: Thanos

This macro for Laravel Collections will randomly delete half the items in a collection.

Installation

Install in your Laravel project via composer:

composer install chrgriffin/collection-macro-thanos

If your version of Laravel supports auto-discovery (versions 5.5 and up), that's it!

For older versions of Laravel, you will need to edit your config/app.php file to include the service provider in your providers array:

return [
    // ...
    'providers' => [
        // ...
        CollectionMacroThanos\ServiceProvider::class
    ]
];

Usage

You should now be able to chain ->thanos() onto any collections to randomly delete half the items in the collection.

$collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
    ->thanos(); // 1, 3, 4, 6, 8