2017 © Pedro Peláez
 

library laravel-hashid-uuid

Shorten UUID encoding for Laravel Hashid.

image

elfsundae/laravel-hashid-uuid

Shorten UUID encoding for Laravel Hashid.

  • Thursday, January 18, 2018
  • by ElfSundae
  • Repository
  • 1 Watchers
  • 5 Stars
  • 63 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 62 % Grown

The README.md

Laravel Hashid UUID

Latest Version on Packagist Software License tests StyleCI SymfonyInsight Grade Quality Score Code Coverage Total Downloads, (*1)

This is a plugin package for Laravel Hashid, it provides an uuid hashid driver to shorten your UUID encoding., (*2)

Installation

You can install this package using the Composer manager:, (*3)

$ composer require elfsundae/laravel-hashid-uuid

For Lumen or earlier Laravel than v5.5, you need to register the service provider manually:, (*4)

ElfSundae\Laravel\Hashid\UuidServiceProvider::class,

Configuration

  • Driver name: uuid
  • Configuration:
    • connection : The hashid connection name for encoding and decoding.

Example:, (*5)

'connections' => [

    'uuid_base62' => [
        'driver' => 'uuid',
        'connection' => 'base62',
    ],

    'uuid_hashids' => [
        'driver' => 'uuid',
        'connection' => 'hashids_string',
    ],

    // ...
],

Usage

Example:, (*6)

use Ramsey\Uuid\Uuid;

$string = 'cd79e206-c715-11e7-891d-8bf37117635e';
$uuid = Uuid::fromString($string);
$hex = $uuid->getHex();                 // "cd79e206c71511e7891d8bf37117635e"

// Encode using the original connections:
hashid_encode($uuid, 'base62');         // "1mUcj8TfpKB7vEBlRecZ4PADhnE1UbBg2L9n3PQOSFqzYZHwj"
hashid_encode($uuid, 'hashids_string'); // "Wr3xrA2WWEh4K1LBBV6vhXL592VVQoSKWnpQB5vkt9DkZxDp6Lsjz945vnRl"

// Encode using the "uuid" driver:
hashid_encode($uuid, 'uuid_base62');    // "6Fj7unqIaNKkq5zbJo1HJ8"
hashid_encode($string, 'uuid_base62');  // "6Fj7unqIaNKkq5zbJo1HJ8"
hashid_encode($hex, 'uuid_base62');     // "6Fj7unqIaNKkq5zbJo1HJ8"
hashid_encode($uuid, 'uuid_hashids');   // "kp2wZkXOBzSMNA3nPxNzSOZJ701"

// Decode
$decoded = hashid_decode('6Fj7unqIaNKkq5zbJo1HJ8', 'uuid_base62');
(string) $decoded;                               // "cd79e206-c715-11e7-891d-8bf37117635e"
$decoded->getDateTime()->format('Y-m-d H:i:s');  // "2017-11-11 19:23:31"

// Decoding failure
(string) hashid_decode('foobar', 'uuid_base62'); // "00000000-0000-0000-0000-000000000000"

Testing

$ composer test

License

This package is open-sourced software licensed under the MIT License., (*7)

The Versions

18/01 2018

dev-master

9999999-dev https://github.com/ElfSundae/laravel-hashid-uuid

Shorten UUID encoding for Laravel Hashid.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid hashid short

18/01 2018

1.0.1

1.0.1.0 https://github.com/ElfSundae/laravel-hashid-uuid

Shorten UUID encoding for Laravel Hashid.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid hashid short

11/11 2017

1.0.0

1.0.0.0 https://github.com/ElfSundae/laravel-hashid-uuid

Shorten UUID encoding for Laravel Hashid.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid hashid short