antoninmasek/laravel-hashids

Simple Laravel wrapper around Hashids library.
13,645
Install
composer require antoninmasek/laravel-hashids
Latest Version:1.1.0
PHP:^8.1
Laravel:10 · 11 · 12
Older releases:9
License:MIT
Last Updated:Jun 11, 2025
Links: GitHub  ·  Packagist
Maintainer: antoninmasek

Simple Laravel wrapper around Hashids library

Packagist Version GitHub Actions Tests Workflow Status Packagist Downloads

This package introduces a simple fluent interface for Hashids package.

Installation

You can install the package via composer:

composer require antoninmasek/laravel-hashids

You can publish the config file with:

php artisan vendor:publish --tag="hashids-config"

This is the contents of the published config file:

return [
    /**
     * If you wish to globally redefine the default alphabet you may do so below. If set to
     * null, then the default value defined in the Hashids library is used.
     *
     * Please make sure your alphabet has at least 16 characters as that is the minimum
     * length of the alphabet the Hashids package requires.
     *
     * The default alphabet choice only includes capital letters, that is to prevent
     * possible issues with case-insensitive collations in databases.
     *
     * @see \Hashids\Hashids::__construct
     */
    'alphabet' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',

    /**
     * If you wish to globally redefine the default salt you may do so below. If set to
     * null, then the default value defined in the Hashids library is used.
     *
     * @see \Hashids\Hashids::__construct
     */
    'salt' => null,

    /**
     * If you wish to globally redefine the default minimum length of the hash you may do so
     * below. If set to null, then the default value defined in the Hashids library is used.
     *
     * Please note, that this is minimum length and not exact length. This means, that if
     * you specify, for example, 5 the resulting hash id can have length of 5 characters
     * or more.
     *
     * @see \Hashids\Hashids::__construct
     */
    'min_length' => null,
];

Usage

use AntoninMasek\Hashids\Facades\Hashids;

Hashids::encode(1);
Hashids::decode('jR');

// With configuration
Hashids::alphabet('1234567890qwertz')->encode(1);
Hashids::salt('your-salt')
    ->minLength(10)
    ->encode(1)

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

Antonín Mašek

License

The MIT License (MIT). Please see License File for more information.

Special thanks

  • To Spatie for their amazing skeleton which I used to scaffold this repository.

Related Packages

coderscantina/hashidable

An adapted bridge for using hashids in Laravel models.

5,072 0
antoninmasek/laravel-model-hashids

Easily use Hashids with Laravel models.

7,329 2
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

644,549,754 9,698
laravel/framework

The Laravel Framework.

593,882,149 34,959

Version History

Version Released PHP Laravel License
1.1.0 ^8.1 ^10.0 || ^11.0 || ^12.0 MIT
1.0.0 ^8.1 ^10.0 || ^11.0 MIT
0.2.0 ^8.1 || ^8.2 ^9.0 || ^10.0 MIT
0.1.0 ^8.0|^8.1 ^9.0 MIT