PHP code example of ashkanrimer / hashids

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

    

ashkanrimer / hashids example snippets


hashid(1); 		// returns the hadhis of 1. ex: rolXo
hashid('rolXo') // returns the equivalent id: 1

hashid_number(1);        // returns 1
hashid_number('rolXo');  // returns 1
hashid_string('rolXo');  // returns 'rolXo'
hashid_string(1);        // returns 'rolXo'

hashid([1,2,3]);     // returns ["rolXo", "bVnxk", "LkGjo"]



namespace App;

use Hashids\HashidsModelTrait;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use HashidsModelTrait;
}

echo $post->id;      // 1
echo $post->hashid;  // rolXo

Post::where('title', 'foo')->withHadhis(["rolXo", "bVnxk", "LkGjo"]);

Post::where('title','foo')->withHashids(["rolXo", 2, "3"])

hashid(1);     // returns 'h1';
hashid('h1');  // returns 1;

hashid(1, "custom");  

use Hashids\Wrapper as Hashid;

Hashid::encode($matter, string $salt_name = "main", $min_length = 5, $alphabet = null);
Hashid::decode(string $matter, string $salt_name = "main", $min_length = 5, $alphabet = null)
bash
php artisan vendor:publish