PHP code example of matt-daneshvar / eloquent-hashids

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

    

matt-daneshvar / eloquent-hashids example snippets


$table->string('hashid')->nullable();

use Illuminate\Database\Eloquent\Model;
use MattDaneshvar\EloquentHashids\Hashid;
use MattDaneshvar\EloquentHashids\HashidRouting;

class Receipt extends Model
{
    use Hashid, HashidRouting;
}

class Receipt extends Model
{
    use Hashid;
    
    /**
     * The column used to store Hashid.
     *
     * @var array
     */
    protected static $hashidColumn = 'hashid';
    
    /**
     * The minimum length of the generated Hashids.
     *
     * @var array
     */
    protected static $hashidMinLength = 8;
    
    /**
     * The whitelist of characters used inside the generated Hashids.
     *
     * @var array
     */
    protected static $hashidChars = 'abcdefghijklmnopqrstuvwxyz1234567890';
    
    /**
     * The salt for generating Hashids.
     *
     * @var array
     */
    protected static $hashidSalt = 'your unique salt';
    
    /**
     * The attribute encoded to generate the Hashid.
     *
     * @var array
     */
    protected static $hashidKey = 'id';
}

class Receipt extends Model
{
    use Hashid;
    
    protected static $hashidColumn = 'uid';
}

 class Receipt extends Model
 {
     use Hashid;
     
     protected static $hashidSalt = 'salt and pepper';
 }
 

class Receipt extends Model
{
    public static function boot()
    {
        parent::boot();
    
        static::$hashidsInstance = new Hashids('salt and pepper', 5);
    }
}

Route::get('api/receipts/{receipt}', function (App\Receipt $receipt) {
    return $receipt->total;
});