Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/torann/laravel-hashids
Laravel package for Hashids
https://github.com/torann/laravel-hashids
hashids laravel
Last synced: 3 days ago
JSON representation
Laravel package for Hashids
- Host: GitHub
- URL: https://github.com/torann/laravel-hashids
- Owner: Torann
- License: bsd-2-clause
- Created: 2014-01-24T18:37:23.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-03-22T18:48:10.000Z (8 months ago)
- Last Synced: 2024-10-20T23:16:00.088Z (19 days ago)
- Topics: hashids, laravel
- Language: PHP
- Homepage:
- Size: 28.3 KB
- Stars: 54
- Watchers: 7
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hashids for Laravel
[![Latest Stable Version](https://poser.pugx.org/torann/hashids/v/stable.png)](https://packagist.org/packages/torann/hashids) [![Total Downloads](https://poser.pugx.org/torann/hashids/downloads.png)](https://packagist.org/packages/torann/hashids)
This package uses the classes created by [hashids.org](http://www.hashids.org/ "http://www.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
- [Hashids on Packagist](https://packagist.org/packages/torann/hashids)
- [Hashids on GitHub](https://github.com/torann/laravel-hashids)### Composer
From the command line run:
```bash
$ composer require torann/hashids
```**Without Package Auto-Discovery**
Once Hashids is installed you need to register the service provider and facade with the application. Open up `config/app.php` and find the `providers` and `aliases` keys.
```php
'providers' => [
Torann\Hashids\HashidsServiceProvider::class,
]'aliases' => [
'Hashids' => Torann\Hashids\Facade\Hashids::class,
]
```### Publish the configurations
Run this on the command line from the root of your project:
```
$ php artisan vendor:publish --provider="Torann\Hashids\HashidsServiceProvider"
```A configuration file will be publish to `config/hashids.php`.
## Usage
Once you've followed all the steps and completed the installation you can use Hashids.
### Encoding
You can simply encode a single id:
```php
Hashids::encode(1); // Returns Ri7Bi
```or multiple..
```php
Hashids::encode(1, 21, 12, 12, 666); // Returns MMtaUpSGhdA
```### Decoding
```php
Hashids::decode(Ri7Bi);// Returns
array (size=1)
0 => int 1
```or multiple..
```php
Hashids::decode(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!