PHP code example of elfsundae / laravel-hashid
1. Go to this page and download the library: Download elfsundae/laravel-hashid 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 example snippets
ElfSundae\Laravel\Hashid\HashidServiceProvider::class
'default' => 'id',
'connections' => [
'basic' => [
'driver' => 'base64',
],
'hashids' => [
'driver' => 'hashids',
'salt' => 'sweet girl',
],
'id' => [
'driver' => 'hashids_integer',
'salt' => 'My Application',
'min_length' => 6,
'alphabet' => '1234567890abcdef',
],
'base62' => [
'driver' => 'base62',
'characters' => 'f9FkqDbzmn0QRru7PBVeGl5pU28LgIvYwSydK41sCO3htaicjZoWAJNxH6EMTX',
],
],
use ElfSundae\Laravel\Hashid\Facades\Hashid;
// Obtain the default connection instance
hashid();
Hashid::connection();
// Obtain the "base62" connection instance
hashid('base62');
Hashid::connection('base62');
// Obtain the Base64 driver instance
hashid('base64');
Hashid::connection('base64');
Hashid::driver('base64');
hashid()->encode(123456);
hashid('base64')->decode('TGFyYXZlbA');
Hashid::encode(123456);
Hashid::connection('hashids')->decode('X68fkp');
hashid_encode(123456);
hashid_decode('TGFyYXZlbA', 'base64');
namespace App\Hashid;
use ElfSundae\Laravel\Hashid\DriverInterface;
use Illuminate\Contracts\Encryption\Encrypter;
class CustomDriver implements DriverInterface
{
protected $encrypter;
protected $serialize;
public function __construct(Encrypter $encrypter, array $config = [])
{
$this->encrypter = $encrypter;
$this->serialize = $config['serialize'] ?? false;
}
public function encode($data)
{
return $this->encrypter->encrypt($data, $this->serialize);
}
public function decode($data)
{
return $this->encrypter->decrypt($data, $this->serialize);
}
}
'connections' => [
'custom' => [
'driver' => App\Hashid\CustomDriver::class,
'serialize' => false,
],
// ...
]
$this->app->bind('hashid.driver.custom', CustomDriver::class);
sh
# For Laravel application:
$ php artisan vendor:publish --tag=hashid
# For Lumen application:
$ cp vendor/elfsundae/laravel-hashid/config/hashid.php config/hashid.php