Skip to content

Commit

Permalink
Merge pull request #11 from veelasky/configurable-key
Browse files Browse the repository at this point in the history
Configurable key
  • Loading branch information
veelasky authored Feb 24, 2021
2 parents 245dfbd + d29599e commit 8a80724
Show file tree
Hide file tree
Showing 6 changed files with 910 additions and 150 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,29 @@ HashId::idToHash($id, User::class) // same as User::idToHash($hash);
However you can opt-out to not using any eloquent model or implementing your own logic to the repository.

```php

HashId::make($key, $salt); // will return \HashId\HashId class.

// once you instantiated the object, you can retrieve it on your next operation
HashId::get($key);
```

If you're using single table inheritance model, where you want to has the same calculated hash across all inherited models, use `$hashKey` property, this will result the calculation remain the same across all inherited model.

```php
class User extends Model {
protected $hashKey = 'somethingUnique';
}

class Customer extends Customer {

}

$customer = Customer::find(1);
$user = User::find(1);

$user->hash; // will be equal to $customer->hash
```

You can also specify the length and characters of the hashed Id with `HASHID_LENGTH` and `HASHID_ALPHABET` environment variable respectively, or you can publish the configuration file using this command:

```bash
Expand All @@ -120,3 +136,7 @@ Validator::make([
]);
...
```

#### License

MIT License
Loading

0 comments on commit 8a80724

Please sign in to comment.