PHP code example of danphyxius / hashids

1. Go to this page and download the library: Download danphyxius/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/ */

    

danphyxius / hashids example snippets


  "  "danphyxius/hashids": "1.3"
  }
  

  php composer.phar update
  

  'DanPhyxius\Hashids\HashidsServiceProvider'
  

  'Hashids' => 'DanPhyxius\Hashids\Hashids'
  

  php artisan config:publish danphyxius/hashids
  

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

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

  Hashids::decrypt('Ri7Bi');

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

  Hashids::decrypt('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->encrypt(1);
          return View::make('example.index', compact('hash'));
      }
  }
  

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