GitHub Repository


Hashing your internal ID’s, is very helpful feature for security reasons (to prevent some hack attacks) and business reasons (to hide the real total records from your competitors).

Enable Hash ID

Set the HASH_ID=true in the .env file.

Also with the feature make sure to always use the getHashedKey() on any model, whenever you need to return an ID (mainly from transformers) weather hashed ID or not.


'id' => $user->getHashedKey(),

Note: if the feature is set to false HASH_ID=false the getHashedKey() will return the normal ID.


There are 2 ways an ID’s can be passed to your system via the API:

In URL example:

In parameters example: [GET] or [POST]

in both cases you will need to inform your API about what’s coming form the Request class.

Checkout the Requests page. After setting the $decode and $urlParameters properties on your Request class, the ID will be automatically decoded for you, to apply validation rules on it or/and use it from your controller ($request->id will return the decoded ID).


You can change the default length and characters used in the ID from the config file app/Ship/Configs/hashids.php.


In your tests you must hash the ID’s before making the calls, because if you tell your Request class to decode an ID for you, it will throw an exception when the ID is not encoded.

for Parameter ID’s

Always use getHashedKey() on your models when you want to get the ID


$data = [
    'roles_ids' => [
    'user_id'   => $randomUser->getHashedKey(),
$response = $this->makeCall($data);

*Or you can do this manually Hashids::encode($id);. *

for URL ID’s

You can use this helper function injectId($id, $skipEncoding = false, $replace = '{id}').


$response = $this->injectId($admin->id)->makeCall();

More details on the Tests Helpers page.


You can use the Apiato\Core\Traits\HashIdTrait to any model or class, in order to have the encode and decode functions.

By default you have access to these functions $this->encode($id) and $this->decode($id) from all your Tests class and Controllers.