PHP code example of elfsundae / laravel-hashid-uuid
1. Go to this page and download the library: Download elfsundae/laravel-hashid-uuid library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
elfsundae / laravel-hashid-uuid example snippets
ElfSundae\Laravel\Hashid\UuidServiceProvider::class,
'connections' => [
'uuid_base62' => [
'driver' => 'uuid',
'connection' => 'base62',
],
'uuid_hashids' => [
'driver' => 'uuid',
'connection' => 'hashids_string',
],
// ...
],
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"