Laravel package for Hashids

Overview

Hashids for Laravel 4

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

Begin by installing the package through Composer. Edit your project's composer.json file to require mitch/hashids.

"require": {
  "mitch/hashids": "1.x"
}

Next use Composer to update your project from the the Terminal:

php composer.phar update

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.

'Mitch\Hashids\HashidsServiceProvider'

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

'Hashids' => 'Mitch\Hashids\Hashids'

Now last but not least you need to publish to package configuration from your Terminal:

php artisan config:publish mitch/hashids

Usage

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

Encoding

You can simply encrypt on id:

Hashids::encode(1); // Creating hash... Ri7Bi

or multiple..

Hashids::encode(1, 21, 12, 12, 666); // Creating hash... MMtaUpSGhdA

Decoding

It's the same thing but the other way around:

Hashids::decode('Ri7Bi');

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

or multiple..

Hashids::decode('MMtaUpSGhdA');

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

Injecting Hashids

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

class ExampleController extends BaseController
{
    protected $hashids;

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

    public function getIndex()
    {
        $hash = $this->hashids->encode(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.

Using IoC

Create a Hashids instance with the IoC

App::make('Hashids\Hashids')->encode(1);

That's it!

Documentation about Hashids can be found here.

Thanks to Ivan Akimov (@ivanakimov) for making Hashids. All credits for the Hashids package go to him.

Comments
  • Unable to Install, Version Satisfiable

    Unable to Install, Version Satisfiable

    Hi,

    i've put my require like this '' mitch/hashids": "dev-master" '' but the result error like this when running composer update

    Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages.

    Problem 1 - Removal request for hashids/hashids == 0.3.9999999.9999999-dev - Removal request for hashids/hashids == 9999999-dev - mitch/hashids dev-master requires hashids/hashids * -> satisfiable by hashids/hashids[0.3.x-dev, dev-master]. - Installation request for mitch/hashids dev-master -> satisfiable by mitch/hashids[dev-master].

    opened by fer-ri 4
  • Composer Errors

    Composer Errors

    Hey there,

    If I set composer require as:

    "mitch/hashids": "1.x"

    I get this error

    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - The requested package mitch/hashids could not be found in any version, there may be a typo in the package name.
    

    If I use "mitch/hashids": "1.*@dev"

    Then I get the following error:

    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Installation request for mitch/hashids 1.*@dev -> satisfiable by mitch/hashids[1.x-dev].
        - mitch/hashids 1.x-dev requires hashids/hashids 0.3.x -> no matching package found.
    
    opened by alexleonard 3
  • Compability for PHP 5.3.*

    Compability for PHP 5.3.*

    Call to protected method Mitch\Hashids\HashidsServiceProvider::getSalt() from context
    

    This happens on my webserver which uses php 5.3.17, not sure when it was fixed.

    Explanation: http://www.php.net/manual/en/functions.anonymous.php#98384

    Currently I replaced the functions to public to fix the issue, but not sure that a pullable idea.

    opened by hisorange 2
  • Move settings to separate config

    Move settings to separate config

    Currently it requires changes to start.php, which will get overwritten whenever you upgrade bundles. Instead, please implement support for application/config/hashids.php

    opened by syphernl 2
  • Updating For Laravel 5

    Updating For Laravel 5

    This should be all the changes necessary to make this package compatible with Laravel 5, plus some tweaks to the readme, which I can revert if you would like.

    opened by rydurham 1
  • App Key accessed incorrectly in HashidsServiceProvider

    App Key accessed incorrectly in HashidsServiceProvider

    The latest commit results in the following error when trying to use hashids :

    log.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Cannot use object of type Mitch\Hashids\HashidsServiceProvider as array'

    I believe this can be fixed by changing $me['config'] to $me->app['config'] on line 33 in HashidsServiceProvider.php (assuming you meant to use the Laravel app key as the hashids salt).

    opened by cubicleWar 1
  • Problems loading config

    Problems loading config

    Unfortunatly i'm unable to load hashids, the following error occurs.

    Symfony \ Component \ Debug \ Exception \ FatalErrorException Using $this when not in object context

    The error occurs on line 45 of HashidsServiceProvider.php. I was able to fix (workaround) this, bij replacing line 45 by:

    return \Config::get('hashids::salt');

    Any idea why this error occurs?

    opened by MichMich 1
  • Unable to upgrade

    Unable to upgrade

    Composer seems unable to upgrade this package.

    Problem 1 - mitch/hashids dev-master requires hashids/hashids 0.3.@dev -> no matching package found. - mitch/hashids dev-master requires hashids/hashids 0.3.@dev -> no matching package found. - Installation request for mitch/hashids dev-master -> satisfiable by mitch/hashids[dev-master].

    Any idea how to solve this? Thanks!

    opened by MichMich 1
  • Upgraded hashids.php and removed version specific code from start.php

    Upgraded hashids.php and removed version specific code from start.php

    I upgraded hashids.php to version 0.2.1.

    Went in and changed start.php to remove version specific code as it is no longer needed.

    Removed: hashids.php-5-3.php

    Tested on PHP version 5.3.21 and 5.4.11 using the following code:

    $hash = $hasher->encrypt(1, 2, 3, 4);
    echo "<pre>" . print_r($hash, true) . "</pre>";
    echo "<pre>" . print_r($hasher->decrypt($hash), true) . "</pre>";
    
    opened by tplaner 0
  • Allow optional custom salt

    Allow optional custom salt

    Because I'm using this package in conjunction with the JS version, on the client side, I need to have matching salts but don't wish to expose my app's secret key to the world. This will now look for a package config specific salt before falling back to the app key.

    Also mentioned in #21.

    opened by millar 1
  • Laravel 5

    Laravel 5

    This package won't install on Laravel 5.

    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Conclusion: remove laravel/framework 5.0.x-dev
        - mitch/hashids 1.0 requires illuminate/support 4.x -> satisfiable by laravel/framework[4.0.x-dev, 4.1.x-dev, 4.2.x-dev], illuminate/support[4.0.x-dev, 4.1.x-dev, 4.2.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4, v4.0.1, v4.0.10, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26, v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0-BETA1, v4.2.1, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
        - mitch/hashids 1.x-dev requires illuminate/support 4.x -> satisfiable by laravel/framework[4.0.x-dev, 4.1.x-dev, 4.2.x-dev], illuminate/support[4.0.x-dev, 4.1.x-dev, 4.2.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4, v4.0.1, v4.0.10, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26, v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0-BETA1, v4.2.1, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
        - Can only install one of: laravel/framework[5.0.x-dev, 4.0.x-dev].
        - Can only install one of: laravel/framework[5.0.x-dev, 4.1.x-dev].
        - Can only install one of: laravel/framework[5.0.x-dev, 4.2.x-dev].
        - don't install illuminate/support 4.1.x-dev|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support 4.2.x-dev|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.0|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.1|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.10|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.11|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.12|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.13|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.14|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.15|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.16|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.17|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.18|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.19|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.2|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.20|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.21|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.22|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.23|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.24|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.25|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.26|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.27|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.28|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.29|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.3|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.30|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.4|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.5|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.6|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.7|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.8|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.1.9|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.2.0-BETA1|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.2.1|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.2.2|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.2.3|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.2.4|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.2.5|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.2.6|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.2.7|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.2.8|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.2.9|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support 4.0.x-dev|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.0|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.0-BETA2|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.0-BETA3|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.0-BETA4|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.1|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.10|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.2|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.3|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.4|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.5|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.6|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.7|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.8|don't install laravel/framework 5.0.x-dev
        - don't install illuminate/support v4.0.9|don't install laravel/framework 5.0.x-dev
        - Installation request for laravel/framework ~5.0 -> satisfiable by laravel/framework[5.0.x-dev].
        - Installation request for mitch/hashids 1.x -> satisfiable by mitch/hashids[1.0, 1.x-dev].
    
    opened by RandyBooth 4
Releases(1.0)
Owner
Mitchell van Wijngaarden
Mitchell van Wijngaarden
Laravel Blog Package. Easiest way to add a blog to your Laravel website. A package which adds wordpress functionality to your website and is compatible with laravel 8.

Laravel Blog Have you worked with Wordpress? Developers call this package wordpress-like laravel blog. Give our package a Star to support us ⭐ ?? Inst

Binshops 279 Dec 28, 2022
salah eddine bendyab 18 Aug 17, 2021
Traits used primarily in the v6 package but also available as a helper package for applications

Phalcon Traits This package contains traits with methods that are used for Phalcon v6 onward. It can also be useful to others that want short snippets

The Phalcon PHP Framework 5 Oct 7, 2022
This package is aimed to be a simplistic PHP workflow package that works in a similar fashion to GitHub Actions.

Workflow This package is aimed to be a simplistic PHP workflow package that works in a similar fashion to GitHub Actions. Installation To install this

Steve McDougall 4 Sep 26, 2022
Quick package/plugin/component (repo) lookup for your favourite package managers

Package Managers (Download latest release) Package Repo Search Quick package/plugin/component (repo) lookup for your favourite package managers.

will Farrell 689 Dec 27, 2022
A Simple Linode SDK built for Laravel with @JustSteveKing laravel-transporter package

linode client A Simple Linode client built for Laravel with @JustSteveKing laravel-transporter package Installation You can install the package via co

Samuel Mwangi 2 Dec 14, 2022
Laravel Podcast Manager is a complete podcast manager package for Laravel 5.3+ that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI.

laravelpodcast | A Laravel podcast manager package - v0.0.8 Introduction Laravel Podcast Manager is a complete podcast manager package for Laravel 5.3

Jeremy Kenedy 22 Nov 4, 2022
Laravel-htaccess - a package for dynamically edit .htaccess in laravel

laravel-htaccess a package for dynamically edit .htaccess in laravel use RedirectHtaccess Facade function for add RedirectHtaccess()->add(); return in

Mohammad khazaee 3 Dec 19, 2021
Laravel package for Mailjet API V3 and Laravel Mailjet Mail Transport

Laravel Mailjet Laravel package for handling Mailjet API v3 using this wrapper: https://github.com/mailjet/mailjet-apiv3-php It also provides a mailje

Mailjet 76 Dec 13, 2022
This package is the Laravel Nova integration for justbetter/laravel-magento-prices

Laravel Magento Products Nova This package is the Laravel Nova integration for justbetter/laravel-magento-products. Installation Install the package.

JustBetter 14 Nov 4, 2022
A helpful Laravel package to help me get started in Laravel projects quicker.

Launchpad A helpful Laravel package to help me get started in Laravel projects quicker. This is still a work in progress, so use at your own risk! CLI

Steve McDougall 13 Jun 15, 2023
A laravel library or package for mpesa - Tanzania

THIS PACKAGE IS YET TO BE READY JUST A SKELETON This package is created to help developers intergrate with Vodacom Mpesa Tanzania open api. More infor

Emmanuel Paul Mnzava 5 Dec 11, 2022
Xenon\LaravelBDSms is a sms gateway package for sending text message to Bangladeshi mobile numbers using several gateways like sslcommerz, greenweb, dianahost,metronet in Laravel framework

Xenon\LaravelBDSms is a sms gateway package for sending text message to Bangladeshi mobile numbers using several gateways for Laravel. You should use

Ariful Islam 95 Jan 3, 2023
Laravel package to convert English numbers to Bangla number or Bangla text, Bangla month name and Bangla Money Format

Number to Bangla Number, Word or Month Name in Laravel | Get Wordpress Plugin Laravel package to convert English numbers to Bangla number or Bangla te

Md. Rakibul Islam 50 Dec 26, 2022
Helper for countries laravel package

Countries helper Helper for countries laravel package Installation You can install the package via composer: composer require eliseekn/countries-helpe

Kouadio Elisée N'GUESSAN 1 Oct 15, 2021
A simple laravel package for wallet implementation

wallet A simple laravel package for wallet implementation. This package can basically be plugged into a laravel project and it will handle wallet impl

Ademuyiwa Adetunji 8 Dec 1, 2022
Laravel package to make it easy to use the gorgeous emojis from EmojiOne

laravel-emojione Laravel package to make it easier working with the gorgeous emojis from EmojiOne. Remember to read the EmojiOne Free License and prov

Christoffer Korvald 140 Nov 29, 2022
Easily decorate your method calls with laravel-decorator package

?? Laravel Decorator Decorator pattern in laravel apps Made with ❤️ for smart clean coders A try to port "decorator" feature from python language to l

Iman 126 Jan 1, 2023
Simple laravel package for 2C2P Payment Gateway.

Laravel 2C2P Payment Gateway Simple laravel package for 2C2P Payment Gateway. Installation You can install the package via composer: composer require

null 3 Dec 7, 2021