1. Go to this page and download the library: Download m-wardany/hash-ids 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/ */
m-wardany / hash-ids example snippets
return [
// Default encryption key (can be overridden per attribute)
'encryption_key' => env('HASHID_ENCRYPTION_KEY', env('APP_KEY')),
// Pattern for hashed attribute names (e.g., 'id' becomes 'id_hashed')
'hashed_attributed_pattern' => '%s_hashed',
// Default minimum length for hashed values
'min_length' => 5,
];
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use MWardany\HashIds\Helpers\HashBuilder;
use MWardany\HashIds\Interfaces\Hashable;
use MWardany\HashIds\Traits\HasHashId;
class Post extends Model implements Hashable
{
use HasHashId;
protected $fillable = ['title', 'ref'];
public function getHashAttributes(): array
{
return [
'id' => HashBuilder::mixed('post_key')
->minLength(5)
->prefix('PK-'),
];
}
}