discord-php-helpers/collection
Laravel-inspired collection library for DiscordPHP. Provides a fluent, chainable API for working with arrays and DiscordPHP data—filtering, mapping, sorting, grouping, and more. Install via Composer and use as a lightweight helper in your bot projects.
Install via Composer with composer require discord-php-helpers/collection, then wrap Discord API response arrays in Discord\Helpers\Collection to enable chainable operations. Your first practical use case is processing paginated or iterable payloads — e.g., filtering members, sorting channels, or extracting data from event payloads:
use Discord\Helpers\Collection;
$members = new Collection($guild->members->all());
$onlineDevs = $members
->where('status', 'online')
->filter(fn($m) => Str::contains($m->user->username, 'dev'))
->pluck('user.username')
->values();
Start with the official DiscordPHP Collection Guide for method reference — though note its limited depth compared to Laravel’s documentation.
$client->http->get(...)) in Collection::make() to avoid manual array_map/array_filter boilerplate.$messages = Collection::make($event->messages)
->map(fn($data) => new Message($client, $data))
->where('type', Message::TYPE_DEFAULT)
->sortBy('timestamp')
->values();
$contexts = new Collection($interactions)
->groupBy(fn($i) => $i->member?->user->username ?? 'unknown');
toArray() or jsonSerialize() before caching — collections themselves aren’t directly serializable to JSON in most cases.2026 release date is almost certainly a typo/misconfiguration.collect() helper: Unlike Laravel, there’s no global helper — always import the class explicitly or use new Collection(...).->map()->filter()->sortBy()->map() on large datasets (>1k items) without batching.Collection likely uses CollectionTrait; extending it may cause method signature mismatches or duplicate trait errors. Prefer composition or decorators over subclassing.Collection in unit tests as a simple iterable — it adds minimal abstraction over arrays. If testing logic inside chains, extract inner callbacks into named methods.composer.json ("discord-php-helpers/collection": "dev-main#<commit>") if used, and audit behavior before production.How can I help you explore Laravel packages today?