PHPackages                             m-wardany/hash-ids - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. m-wardany/hash-ids

ActiveLibrary[Security](/categories/security)

m-wardany/hash-ids
==================

This package is designed to hash sequential keys so that they appear as random characters, making them difficult to predict. There is no requirement to check if the key already exists in the database before saving, as each key is guaranteed to be unique

v2.0.1(7mo ago)0719MITPHPPHP ^8.1

Since Jul 8Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/m-wardany/random-id)[ Packagist](https://packagist.org/packages/m-wardany/hash-ids)[ RSS](/packages/m-wardany-hash-ids/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (10)Used By (0)

Hash Id
=======

[](#hash-id)

A Laravel package designed to hash sequential keys into random-appearing characters, making them difficult to predict. Each hashed key is guaranteed to be unique without requiring database existence checks before saving.

Features
--------

[](#features)

- 🔐 **Secure hashing** - Transform sequential IDs into unpredictable hashes
- 🎯 **Multiple hash types** - Support for mixed, text, and integer alphabets
- 🔧 **Flexible configuration** - Customize prefixes, suffixes, and minimum lengths
- 🔑 **Custom encryption keys** - Use different encryption keys per attribute
- 📦 **Multiple hashes** - Generate multiple hash variants for a single attribute
- ✨ **Laravel integration** - Seamless integration with Eloquent models

Installation
------------

[](#installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

```
composer require m-wardany/hash-ids
```

### Step 2: Publish Configuration

[](#step-2-publish-configuration)

```
php artisan vendor:publish --provider="MWardany\HashIds\Providers\ServiceProvider"
```

This will create a `config/hashid.php` file where you can customize the default settings.

Configuration
-------------

[](#configuration)

Update `config/hashid.php` to set your global defaults:

```
return [
    // Default encryption key (can be overridden per attribute)
    'encryption_key' => env('HASHID_ENCRYPTION_KEY', env('APP_KEY')),

    // Pattern for hashed attribute names (e.g., 'id' becomes 'id_hashed')
    'hashed_attributed_pattern' => '%s_hashed',

    // Default minimum length for hashed values
    'min_length' => 5,
];
```

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

To use hash IDs in your model, implement the `Hashable` interface and use the `HasHashId` trait:

```
