PHPackages                             guava/sqids-for-laravel - 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. guava/sqids-for-laravel

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

guava/sqids-for-laravel
=======================

This is a laravel wrapper for sqids.

1.2.0(1y ago)142.4k1MITPHPPHP ^8.2CI passing

Since Feb 10Pushed 1y ago2 watchersCompare

[ Source](https://github.com/GuavaCZ/sqids-for-laravel)[ Packagist](https://packagist.org/packages/guava/sqids-for-laravel)[ Docs](https://github.com/GuavaCZ/sqids-for-laravel)[ GitHub Sponsors](https://github.com/GuavaCZ)[ RSS](/packages/guava-sqids-for-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (9)Versions (5)Used By (0)

[![sqids-for-laravel Banner](docs/images/banner.jpg)](docs/images/banner.jpg)

Laravel wrapper for Sqids
=========================

[](#laravel-wrapper-for-sqids)

[![Latest Version on Packagist](https://camo.githubusercontent.com/63e3ea350b677798e0f98d4401bf2b7b978565d26d8d569cd9bc00d0a6a75ac6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67756176612f73716964732d666f722d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/guava/sqids-for-laravel)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c6537cf52ee67045530c110a38d3f806bd0f87e0ee4d2fb090de71fdb8c4c98d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6775617661435a2f73716964732d666f722d6c61726176656c2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/guavaCZ/sqids-for-laravel/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/bf03640f10b33ec2ad0a016f7e9374be6b8241b2ea919d666f24c16ae7d4b695/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f67756176612f73716964732d666f722d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/guava/sqids-for-laravel)

Laravel Wrapper for [sqids.org](https://sqids.org) PHP library.

Support us
----------

[](#support-us)

Your support is key to the continual advancement of our plugin. We appreciate every user who has contributed to our journey so far.

While our plugin is available for all to use, if you are utilizing it for commercial purposes and believe it adds significant value to your business, we kindly ask you to consider supporting us through GitHub Sponsors. This sponsorship will assist us in continuous development and maintenance to keep our plugin robust and up-to-date. Any amount you contribute will greatly help towards reaching our goals. Join us in making this plugin even better and driving further innovation.

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

[](#installation)

You can install the package via composer:

```
composer require guava/sqids-for-laravel
```

Usage
-----

[](#usage)

This package adds a slightly modified version of the Sqids class, which allows a fluent configuration of all options. It also adds a salting option.

### Generating Sqids

[](#generating-sqids)

There's multiple ways you can use this package to generate sqids:

```
// Via our Facade
use Guava\Sqids\Facades\Sqids;

Sqids::encode([1,2,3]); /// Outputs '86Rf07'

// Via a classic instance
use Guava\Sqids\Sqids;
$sqids = new Sqids();
$sqids->encode([1,2,3]); /// Outputs '86Rf07'

// Via the app container / dependency injection
use Guava\Sqids\Sqids;
app(Sqids::class)->encode([1,2,3]); /// Outputs '86Rf07'

// Via our factory method, which simply returns an instance of Sqids
// The factory method is also available on the facade class
use Guava\Sqids\Sqids;
Sqids::make()->encode([1,2,3]);
```

It's entirely up to you which way you prefer. In our examples, we will make use of the factory method.

### Using in Eloquent Models

[](#using-in-eloquent-models)

This package also comes with a trait that you can use in your Eloquent models. This trait will automatically add a sqid attribute which will be created from the model's primary key.

```
use \Illuminate\Database\Eloquent\Model;
use \Guava\Sqids\Concerns\HasSqids;

class YourModel extends Model {
    use HasSqids;

    // ...
}
```

That's it! Now you can access the `sqid` attribute on your model.

You can custimize how the sqid on your model is generated by overriding the `getSqids` method:

```
use \Illuminate\Database\Eloquent\Model;
use \Guava\Sqids\Concerns\HasSqids;
use \Guava\Sqids\Sqids;

class YourModel extends Model {
    use HasSqids;

    // ...

    protected function getSqids(): Sqids
    {
        return Sqids::make()
            ->salt() // This will use the model's class name as the salt, so every model generates different IDs
             // ... add more options here
        );
    }
}
```

### Route binding

[](#route-binding)

If you want to be able to use the `sqid` as the route key, simply add the `HasSqidsRouting` trait to your model:

```
use \Illuminate\Database\Eloquent\Model;
use \Guava\Sqids\Concerns\HasSqids;
use \Guava\Sqids\Concerns\HasSqidsRouting;

class YourModel extends Model {
    use HasSqids, HasSqidsRouting;

    // ...
}
```

### Options

[](#options)

#### Customizing the alphabet

[](#customizing-the-alphabet)

```
use Guava\Sqids\Sqids;

Sqids::make()
->alphabet('0123456789abcdef')
->encode([1,2,3]); /// Outputs 'c9bf67'
```

#### Customizing the minLength

[](#customizing-the-minlength)

```
use Guava\Sqids\Sqids;

Sqids::make()
->minLength('8')
->encode([1,2,3]); /// Outputs '86Rf07xd'
```

#### Customizing the block list

[](#customizing-the-block-list)

```
use Guava\Sqids\Sqids;

Sqids::make()
->blocklist(['86Rf07'])
->encode([1,2,3]); /// Outputs 'se8ojk'
```

#### Salting

[](#salting)

Salting can be used to generate different IDs based on the provided salt, which can be any string or integer.

```
use Guava\Sqids\Sqids;

Sqids::make()
->salt('my-salt')
->encode([1,2,3]); /// Outputs 'rx035W'
```

Salting is especially useful when used on Models with the `HasSqids` trait and you want every model to return different, unique IDs.

So for example a record of `Model1` with the ID 1 has a different sqid that a record of `Model2` with the ID 1.

```
use \Illuminate\Database\Eloquent\Model;
use \Guava\Sqids\Concerns\HasSqids;
use \Guava\Sqids\Sqids;

class YourModel extends Model {
    use HasSqids;

    // ...

    protected function getSqids(): Sqids
    {
        return Sqids::make()
            ->salt() // This will use the model's class name as the salt, so every model generates different IDs
        );
    }
}
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Lukas Frey](https://github.com/lukas-frey)
- [All Contributors](../../contributors)
- Spatie - Our package skeleton is a modified version of [Spatie's Package Skeleton](https://github.com/spatie/package-skeleton-laravel)
-

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance44

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.3% 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 ~127 days

Total

4

Last Release

442d ago

PHP version history (2 changes)1.0.0PHP ^8.1

1.1.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/42d872f5f47cd71cfd46c8fbd6ec77a6bfb46d6d9499b5e1f843eb407c07f737?d=identicon)[Skrypt](/maintainers/Skrypt)

---

Top Contributors

[![lukas-frey](https://avatars.githubusercontent.com/u/10926334?v=4)](https://github.com/lukas-frey "lukas-frey (13 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelGuavasqids-for-laravel

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/guava-sqids-for-laravel/health.svg)

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

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[guava/calendar

Adds support for vkurko/calendar to Filament PHP.

298241.0k3](/packages/guava-calendar)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)

PHPackages © 2026

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