PHP code example of alexander-fuchs / hashidable

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

    

alexander-fuchs / hashidable example snippets


use Altinum\Hashidable\Hashidable;

Class User extends Model
{
  use Hashidable;
}

$user = User::find(1);

$user->id; // 1
$user->hashid; // 3RwQaeoOR1E7qjYy

User::find(1);
User::findByHashId('3RwQaeoOR1E7qjYy');
User::findByHashidOrFail('3RwQaeoOR1E7qjYy');

Route::apiResource('users', UserController::class);

public function show(Request $request, User $user)
{
  return $user; // Works just fine
}

return [
    /**
     * Length of the generated hashid.
     */
    'length' => 16,

    /**
     * Character set used to generate the hashids.
     */
    'charset' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',

    /**
     * Prefix attached to the generated hash.
     */
    'prefix' => '',

    /**
     * Suffix attached to the generated hash.
     */
    'suffix' => '',

    /**
     * If a prefix of suffix is defined, we use this as a separator
     * between the prefix/suffix.
     */
    'separator' => '-',
];

    public function hashidableConfig()
    {
        return ['prefix' => 'app'];
    }

php artisan vendor:publish --tag=hashidable.config