PHP code example of lava83 / laravel-sqid

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

    

lava83 / laravel-sqid example snippets


use Lava83\LaravelSqid\Facades\LaravelSqid;

LaravelSqid::encode([1, 2, 3]);   // "86Rf07"
LaravelSqid::decode('86Rf07');    // Collection: [1, 2, 3]

use Sqids\Sqids;

return [
    'min_length' => env('LARAVEL_SQID_MIN_LENGTH', Sqids::DEFAULT_MIN_LENGTH),
    'alphabet' => env('LARAVEL_SQID_ALPHABET', Sqids::DEFAULT_ALPHABET),
    'blocklist' => env('LARAVEL_SQID_BLOCKLIST', Sqids::DEFAULT_BLOCKLIST),
];

use Lava83\LaravelSqid\Facades\LaravelSqid;

// Encode an array or a Collection of integers
LaravelSqid::encode([1, 2, 3]);          // "86Rf07"
LaravelSqid::encode(collect([1, 2, 3])); // "86Rf07"

// Decode back into a Collection<int>
LaravelSqid::decode('86Rf07');           // collect([1, 2, 3])

sqid_encode([1, 2, 3]);   // "86Rf07"
sqid_decode('86Rf07');    // collect([1, 2, 3])

collect([1, 2, 3])->sqidsEncode(); // "86Rf07"

use Lava83\LaravelSqid\Exceptions\OnlyIntegersCanBeSqidEncoded;

LaravelSqid::encode([1, 2, 'foo']); // throws OnlyIntegersCanBeSqidEncoded
bash
php artisan vendor:publish --tag="laravel-sqid-config"