Skip to content

Add collection macros for encoding and decoding #17

@Alig96

Description

@Alig96

I'm working with multiple arrays of encoded/decoded ids and found it helpful to register 2 macros for encoding and decoding the whole collection. Thought I would share to either be implemented or someone can use.

Register within a service provider:

        // Optimus decode
        Collection::macro('decode', function ($connection) {
            return $this->map(function ($value) use ($connection) {
                return $connection->decode($value);
            });
        });

        // Optimus encode
        Collection::macro('encode', function ($connection) {
            return $this->map(function ($value) use ($connection) {
                return $connection->encode($value);
            });
        });

Use by passing a optimus connection and the collection will return an encoded/decoded version;

$collection->encode(Optimus::connection('Main'));
$collection->decode(Optimus::connection('Main'));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions