Skip to content

A small PHP class to generate YouTube-like ids from one or many numbers. Use hashids when you do not want to expose your database ids to the user.

Notifications You must be signed in to change notification settings

9IPHP/hashids-laravel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hashids for Laravel

A hashids (hashids) wrapper for Laravel.

Hashids is a small PHP class to generate YouTube-like ids from one or many numbers. Use hashids when you do not want to expose your database ids to the user.

Installation

require package in composer.json

"require": {
    "specs/hashids-laravel": "^0.1"
},

add hashids’s service provider in config/app.php

'providers' => array(

    Illuminate\Validation\ValidationServiceProvider::class,
    ...
    Illuminate\View\ViewServiceProvider::class,

    Specs\Hashids\HashidsServiceProvider::class,
),

and hashids’s facade (also in config/app.php)

'aliases' => array(

    'App' => Illuminate\Support\Facades\App::class,
    ...
    'View' => Illuminate\Support\Facades\View::class,

    'Hashids' => Specs\Hashids\HashidsFacade::class,

),

You should also publish the config file.

php artisan vendor:publish --tag=config

And then reset the default values in config/hashids.php.

Example Usage

Use Hashids Facade:

$id = Hashids::encode(1, 2, 3);
$numbers = Hashids::decode($id);

var_dump($id, $numbers);
string(5) "laHquq"
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

More usage

About

A small PHP class to generate YouTube-like ids from one or many numbers. Use hashids when you do not want to expose your database ids to the user.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages