2017 © Pedro Peláez
 

library hashids

Laravel package for Hashids

image

danphyxius/hashids

Laravel package for Hashids

  • Thursday, September 11, 2014
  • by DanPhyxius
  • Repository
  • 1 Watchers
  • 0 Stars
  • 217 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 23 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Hashids for Laravel 4

This package uses the classes created by hashids.org, (*1)

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

Installation

Begin by installing the package through Composer. Edit your project's composer.json file to require ludo237/hashids., (*3)

php "require": { "danphyxius/hashids": "1.3" }, (*4)

Next use Composer to update your project from the the Terminal:, (*5)

php php composer.phar update, (*6)

Once the package has been installed you'll need to add the service provider. Open your app/config/app.php configuration file, and add a new item to the providers array., (*7)

php 'DanPhyxius\Hashids\HashidsServiceProvider', (*8)

After doing this you also need to add an alias. In your app/config/app.php file, add this to the aliases array., (*9)

php 'Hashids' => 'DanPhyxius\Hashids\Hashids', (*10)

Now last but not least you need to publish to package configuration from your Terminal:, (*11)

php php artisan config:publish danphyxius/hashids, (*12)

Usage

Once you've followed all the steps and completed the installation you can use Hashids., (*13)

Encrypting

You can simply encrypt on id:, (*14)

php Hashids::encrypt(1); // Creating hash... Ri7Bi, (*15)

or multiple.., (*16)

php Hashids::encrypt(1, 21, 12, 12, 666); // Creating hash... MMtaUpSGhdA, (*17)

Decrypting

It's the same thing but the other way around:, (*18)

```php Hashids::decrypt('Ri7Bi');, (*19)

// Returns array (size=1) 0 => int 1 ```, (*20)

or multiple.., (*21)

```php Hashids::decrypt('MMtaUpSGhdA');, (*22)

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

Injecting Hashids

Now it's also possible to have Hashids injected into your class. Lets look at this controller as an example.., (*24)

```php class ExampleController extends BaseController { protected $hashids;, (*25)

  public function __construct(Hashids\Hashids $hashids)
  {
      $this->hashids = $hashids;
  }

  public function getIndex()
  {
      $hash = $this->hashids->encrypt(1);
      return View::make('example.index', compact('hash'));
  }

} ``` The original classname and namespace has been bound in the IoC container to return our instantiated Hashids class., (*26)

Using IoC

Create a Hashids instance with the IoC, (*27)

php App::make('Hashids\Hashids')->encrypt(1);, (*28)

That's it!

For documentation about Hashids itself, go to: https://github.com/ivanakimov/hashids.php., (*29)

Hopefully you'll enjoy this package and thanks to Ivan Akimov (@ivanakimov) for making Hashids. All credits for the Hashids package go to him., (*30)

The Versions

11/09 2014

dev-master

9999999-dev

Laravel package for Hashids

  Sources   Download

MIT

The Requires

 

by Avatar DanPhyxius

laravel security hashids hashing

11/09 2014

v1.3

1.3.0.0

Laravel package for Hashids

  Sources   Download

MIT

The Requires

 

by Avatar DanPhyxius

laravel security hashids hashing

11/09 2014

v1.2

1.2.0.0

Laravel package for Hashids

  Sources   Download

MIT

The Requires

 

by Avatar DanPhyxius
by Claudio Ludovico Panetta

laravel security hashids hashing

21/07 2014

v1.1

1.1.0.0

Laravel package for Hashids

  Sources   Download

The Requires

 

by Claudio Ludovico Panetta