---
agentTools:
  projectIndex: https://lavalite.readme.io/llms.txt
---

# Hashids

Laravel 5 wrapper for the [Hashids](http://hashids.org)

[Hashids](http://hashids.org) is a small open-source library that generates short, unique, non-sequential ids from numbers.

## Configuration

Litepie Hashids requires connection configuration. You can edit the configuration file on `config/hashids.php`

## Usage

#### Litepie\Support\Facades\Hashids

This facade will dynamically pass static method calls to the `hashids` object in the ioc container .

### Examples

Here you can see an example of just how simple this package is to use.

[block:code]
{
  "codes": [
    {
      "code": "// You can alias this in config/app.php.\nuse Litepie\\Support\\Facades\\Hashids;\n\nHashids::encode(4815162342);\n// We're done here - how easy was that, it just works!\n\nHashids::decode('doyouthinkthatsairyourebreathingnow');\n// This example is simple and there are far more methods available.",
      "language": "php"
    }
  ]
}
[/block]

[block:api-header]
{
  "type": "basic",
  "title": "Helpers"
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "\n\nhashids_encode(4815162342);\n// We're done here - how easy was that, it just works!\n\nhashids_decode('doyouthinkthatsairyourebreathingnow');\n// This example is simple and there are far more methods available.",
      "language": "php"
    }
  ]
}
[/block]

[block:api-header]
{
  "type": "basic",
  "title": "Traits"
}
[/block]

You can use hashids traits to decode id (primary key) of the model.

[block:code]
{
  "codes": [
    {
      "code": "<?php\n\nuse Litepie\\Database\\Model;\n\nuse Litepie\\Hashids\\Traits\\Hashids;\n\nclass MyModel extends Model\n{\n    use Hashids;\n\n    ......\n}\n",
      "language": "text"
    }
  ]
}
[/block]

This trait overrides two model methods.

```
$model->getRouteKey()
$model->findorFail($hashed_id)
```