Skip to content

Torann/laravel-hashids

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hashids for Laravel 4.1

Latest Stable Version Total Downloads

This package uses the classes created by hashids.org

Generate hashes from numbers, like YouTube or Bitly. Use hashids when you do not want to expose your database ids to the user.


Installation

To get the latest version of Hashids simply require it in your composer.json file.

"torann/hashids": "dev-master"

You'll then need to run composer install to download it and have the autoloader updated.

Once Hashids is installed you need to register the service provider with the application. Open up app/config/app.php and find the providers key.

'Torann\Hashids\HashidsServiceProvider'

There is no need to add the Facade, the package will add it for you.

Publish the config

Run this on the command line from the root of your project:

$ php artisan config:publish torann/hashids

This will publish Hashids' config to app/config/packages/torann/hashids/.

Usage

Once you've followed all the steps and completed the installation you can use Hashids.

Encrypting

You can simply encrypt on id:

Hashids::encrypt(1); // Returns Ri7Bi

or multiple..

Hashids::encrypt(1, 21, 12, 12, 666); // Returns MMtaUpSGhdA

Decrypting

Hashids::decrypt(Ri7Bi);

// Returns
array (size=1)
0 => int 1

or multiple..

Hashids::decrypt(MMtaUpSGhdA);

// Returns
array (size=5)
0 => int 1
1 => int 21
2 => int 12
3 => int 12
4 => int 666

All credit for Hashids goes to Ivan Akimov (@ivanakimov), thanks to for making it!

About

Laravel package for Hashids

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages