PHPackages                             a-sabagh/laravel-sqids - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. a-sabagh/laravel-sqids

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

a-sabagh/laravel-sqids
======================

Laravel integration for sqids-php: Generate short YouTube-looking IDs from numbers

v1.1.0(8mo ago)5165MITPHPPHP ^8.1

Since Aug 22Pushed 8mo agoCompare

[ Source](https://github.com/a-sabagh/laravel-sqids)[ Packagist](https://packagist.org/packages/a-sabagh/laravel-sqids)[ RSS](/packages/a-sabagh-laravel-sqids/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (3)Used By (0)

Laravel Sqids
=============

[](#laravel-sqids)

[![Packagist](https://camo.githubusercontent.com/d5d271398eb13d7049255d8e12a79eff5b194b443072697558e8d552e7521198/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f612d7361626167682f6c61726176656c2d73716964732e737667)](https://packagist.org/packages/a-sabagh/laravel-sqids)[![License](https://camo.githubusercontent.com/4a7faa2278b42e0aff490f6575167aabecbb734cc18692a349eaac9e0918665c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f612d7361626167682f6c61726176656c2d73716964732e737667)](LICENSE)

Laravel adapter for [sqids-php](https://github.com/sqids/sqids-php).
Generate short, unique, non-sequential IDs for your models, routes, validation, and more.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Simple Encode &amp; Decode](#simple-encode--decode)
    - [Usage](#usage)
    - [Encode and Decode Single Integer](#encode-and-decode-single-integer)
    - [Decode and get a Laravel Collection](#decode-and-get-a-laravel-collection)
- [Configuration](#configuration)
    - [Publish the Config File](#publish-the-config-file)
    - [Driver Setup](#driver-setup)
    - [Check if an Encoded String is Valid](#check-if-an-encoded-string-is-valid)
- [Sqids Custom Validation Rule](#sqids-custom-validation-rule)
    - [Available Helpers](#available-helpers)

---

Features
--------

[](#features)

- Generate short, unique, non-sequential IDs
- Easy helpers: `sqid($id)` / `unsqid($hash)`
- Facade: `Sqids::encode()` / `decode()`
- Validation rule: `sqid`
- Fully configurable alphabet, min length, and blocklist

---

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

[](#installation)

```
composer require a-sabagh/laravel-sqids
```

Simple Encode &amp; Decode
--------------------------

[](#simple-encode--decode)

The `Sqids` service allows you to **convert integers into short, URL-safe strings** and decode them back.

Important

Sqids require either the [`bcmath`](https://secure.php.net/manual/en/book.bc.php) or [`gmp`](https://secure.php.net/manual/en/book.gmp.php) extension in order to work.

### Usage

[](#usage)

```
use ASabagh\LaravelSqids\Facades\Sqids;

$id = 123;

$encodeString = Sqids::encode([$id]); // e.g. "Lqj8a0"

$decodeNumber = Sqids::decode($encodeString); // [123]
```

### Encode and Decode Single Integer

[](#encode-and-decode-single-integer)

```
$id = 456;

$encodeString = Sqids::encodeInteger($id);

$decodeInteger = Sqids::decodeInteger($encodeString);
```

### Decode and get a Laravel Collection

[](#decode-and-get-a-laravel-collection)

```
$decodeCollection = Sqids::decodeCollect($encodeString);
```

Notes:

- `encode` always expects an array of integers.
- `decode` returns an array.
- `encodeInteger` / `decodeInteger` work with single integers.
- `decodeCollect` returns a `Collection` for easier chaining with Laravel collections.

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

[](#configuration)

Laravel Sqids allows you to customize its behavior via a configuration file. Publishing the configuration lets you modify settings such as the alphabet, minimum length, and blocklist.

### Publish the Config File

[](#publish-the-config-file)

Use the following Artisan command to publish the configuration to your application:

```
php artisan vendor:publish --tag=sqids
```

Here are each of the drivers setup for your application. Example configuration has been included, but you may add as many drivers as you would like.

```
'drivers' => [
  'default' => [
    'pad' => env('SQIDS_DEFAULT_PAD', ''),
    'length' => env('SQIDS_DEFAULT_LENGTH', 6),
    'blocklist' => env('SQIDS_DEFAULT_BLOCK_LIST', []),
    'alphabet' => env('SQIDS_DEFAULT_ALPHABET', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'),
  ],
]
```

Laravel Sqids allows you to publish the configuration and define multiple drivers, each with its own settings.

### Driver Setup

[](#driver-setup)

The configuration file includes a `drivers` array. You can configure one or more drivers for different encoding strategies.

You can add additional drivers with their own configuration:

```
'drivers' => [
    'default' => [ /* default config */ ],

    'short_ids' => [
        'pad'       => '0',
        'length'    => 4,
        'blocklist' => ['0', 'O', 'I', '1'],
        'alphabet'  => 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789',
    ],
],
```

Then, you can use a specific driver when encoding/decoding:

```
$encoded = Sqids::driver('short_ids')->encode([$id]);
$decoded = Sqids::driver('short_ids')->decode($encoded);
```

Once a driver has been registered and configured in your `config/sqids.php`, you can access it directly using a **camelCase method** on the `Sqids` Facade.

```
$shortId = Sqids::shortIds()->encode([$id]);
$defaultId = Sqids::default()->encode([$id]);
```

#### Check if an Encoded String is Valid

[](#check-if-an-encoded-string-is-valid)

```
$isValid = Sqids::encodedStringValid($randomString);
```

Sqids Custom Validation Rule
----------------------------

[](#sqids-custom-validation-rule)

Laravel Sqids provides a **custom validation rule** to ensure that a given input is a valid Sqid string. You can use it in form requests, inline validation, and with custom drivers.

```
$encoded = Sqids::encodeInteger($id);

$validator = Validator::make(
    ['endpoint' => $encoded],
    ['endpoint' => [new SqidsValidationRule]]
);

if ($validator->passes()) {
    // Valid Sqid
}
```

### Available Helpers

[](#available-helpers)

Function`sqids(array $numbers, ?string $driver = null): string``unsqids(string $encodedString, ?string $driver = null): array``sqidsInt(int $id, ?string $driver = null): int``unsqidsInt(string $encodedString, ?string $driver = null): int``unsqidsCollect(string $encodedString, ?string $driver = null): Collection````
// Encode multiple numbers
$encoded = sqids([1, 2, 3]); // e.g. "Lqj8a0"

// Decode back
$decoded = unsqids($encoded); // [1, 2, 3]

// Encode a single integer
$singleEncoded = sqidsInt(123); // e.g. "M7k2b1"

// Decode single integer
$singleDecoded = unsqidsInt($singleEncoded); // 123

// Decode into a Collection
$collection = unsqidsCollect($encoded); // Collection([1, 2, 3])
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance59

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

260d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f589c5263d4d47f0dc302a25c90e3c5c2832be21618be18c69c3bc746b6eface?d=identicon)[a-sabagh](/maintainers/a-sabagh)

---

Top Contributors

[![a-sabagh](https://avatars.githubusercontent.com/u/24961943?v=4)](https://github.com/a-sabagh "a-sabagh (72 commits)")

---

Tags

laravelidshashidssqidsshort-quick-idsshort-quality-ids

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/a-sabagh-laravel-sqids/health.svg)

```
[![Health](https://phpackages.com/badges/a-sabagh-laravel-sqids/health.svg)](https://phpackages.com/packages/a-sabagh-laravel-sqids)
```

###  Alternatives

[vinkla/hashids

A Hashids bridge for Laravel

2.1k13.3M73](/packages/vinkla-hashids)[sqids/sqids

Generate short YouTube-looking IDs from numbers

5781.4M33](/packages/sqids-sqids)[cybercog/laravel-optimus

An Optimus bridge for Laravel. Id obfuscation based on Knuth's multiplicative hashing method.

192564.1k](/packages/cybercog-laravel-optimus)[red-explosion/laravel-sqids

Easily generate Stripe/YouTube looking IDs for your Laravel models.

4530.8k](/packages/red-explosion-laravel-sqids)[lingxi/hashids

A Hashids bridge for Laravel

183.3k](/packages/lingxi-hashids)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
