seguce92/laravel-hashid

Hashid for Laravel framework.

v2.2.1 2019-06-25 02:45 UTC

This package is auto-updated.

Last update: 2024-10-28 01:31:08 UTC


README

Install

$ composer require seguce92/laravel-hashid

Add service provider in 'config/app.php'

'providers' => [
    ...
    Seguce92\LaravelHashid\ServiceProvider::class,
    ...
],

Add alias in 'config/app.php' (optionnal)

'aliases' => [
    ...
    'Hashid' => Seguce92\LaravelHashid\Facade::class,
    ...
],

Publish configuration

$ php artisan vendor:publish

Configuration

/**
 * Min lenght of generated Hashid
 */
'min_lenght' => 8,

/*
 * Alphabet use in Hashid generation
 */
'alphabet'   => 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789',

Usage

// without custom value salt (default is app key and 'laravel-hashid')
$hashid = Hashid::encode($id); // return string

$id = Hashid::decode($hasid); // return integer

// with custom value salt
$hashid = Hashid::encode($id, $salt); // return string

$id = Hashid::decode($hasid, $salt); // return integer