Download the PHP package elfsundae/laravel-hashid without Composer
On this page you can find all versions of the php package elfsundae/laravel-hashid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-hashid
Laravel Hashid
Laravel Hashid provides a unified API across various drivers such as Base62, Base64, Hashids and Optimus, with support for multiple connections or different encoding options. It offers a simple, elegant way to obfuscate your data by generating reversible, non-sequential, URL-safe identifiers.
- Installation
- Configuration
- Usage
- Built-in Drivers
- Base62
- Base64
- Hashids
- Hex
- Optimus
- Custom Drivers
- Testing
- License
Installation
You can install this package using the Composer manager:
For Lumen or earlier Laravel than v5.5, you need to register the service provider manually:
Then publish the configuration file:
Configuration
Our well documented configuration file is extremely similar to the configurations of numerous Laravel manager integrations such as Database, Queue, Cache and Filesystem. So you do not need to spend extra time to learn how to configure Hashid.
Additionally, for simplicity you do not need to add singleton drivers like Base64 to your config file as they have no encoding options, unless you would like to specify a meaningful connection name.
Let's see an example of the configuration:
Usage
The hashid()
helper or the Hashid
facade may be used to interact with any of your configured connections or drivers:
There are only two methods you need to know to use any connection or driver:
encode($data)
for encoding data.decode($data)
for decoding data.
And there are also two corresponding helper functions:
hashid_encode($data, $name = null)
hashid_decode($data, $name = null)
Built-in Drivers
Base62
- Drivers:
base62
,base62_integer
- Configuration:
characters
: 62 unique characters
- Backend:
tuupola/base62
- Notes:
- You may use the
hashid:alphabet
command to generate random characters. - GMP is strongly recommended as it is much faster than pure PHP.
- You may use the
Base64
- Drivers:
base64
,base64_integer
- Backend:
elfsundae/urlsafe-base64
Hashids
- Drivers:
hashids
,hashids_hex
,hashids_integer
,hashids_string
- Configuration:
salt
min_length
alphabet
: At least 16 unique characters
- Backend:
hashids/hashids
- Notes:
- You may use the
hashid:alphabet
command to generate a random alphabet. - GMP is strongly recommended.
- You may use the
Hex
- Drivers:
hex
,hex_integer
Optimus
- Drivers:
optimus
- Configuration:
prime
: Large prime number lower than2147483647
inverse
: The inverse prime so that(PRIME * INVERSE) & MAXID == 1
random
: A large random integer lower than2147483647
- Backend:
jenssegers/optimus
- Notes:
- You may use the
hashid:optimus
command to generate needed numbers. - Only for integer numbers.
- The max number can be handled correctly is
2147483647
.
- You may use the
Custom Drivers
To create a custom Hashid driver, you only need to implement the ElfSundae\Laravel\Hashid\DriverInterface
interface that contains two methods: encode
and decode
. The constructor can optionally receive the driver configuration from a $config
argument, and type-hinted dependencies injection is supported as well:
Now you can configure the connection with this driver:
If you prefer a short name for your driver, just register a container binding with hashid.driver.
prefix:
Testing
License
This package is open-sourced software licensed under the MIT License.
All versions of laravel-hashid with dependencies
illuminate/support Version ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/console Version ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
tuupola/base62 Version ^2.0
elfsundae/urlsafe-base64 Version ^1.1
hashids/hashids Version ^2.0.4|^3.0|^4.0|^5.0
jenssegers/optimus Version ^1.0