PHP code example of mitch / hashids

1. Go to this page and download the library: Download mitch/hashids library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mitch / hashids example snippets


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

  php composer.phar update
  

  'Mitch\Hashids\HashidsServiceProvider'
  

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

  php artisan config:publish mitch/hashids
  

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

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

  Hashids::decode('Ri7Bi');

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

  Hashids::decode('MMtaUpSGhdA');

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

  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'));
      }
  }
  

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