PHP code example of red-explosion / laravel-sqids

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

    

red-explosion / laravel-sqids example snippets


use RedExplosion\Sqids\Concerns\HasSqids;

class User extends Authenticatable
{
    use HasSqids;
}

$user = User::first();

$sqid = $user->sqid; // use_A3EyoEb2TO

use RedExplosion\Sqids\Concerns\HasSqids;

class User extends Authenticatable
{
    use HasSqids;
    
    protected string $sqidPrefix = 'user';
}

$user = User::first();
$sqid = $user->sqid; // user_A3EyoEb2TO

$user = User::findBySqid('use_A3EyoEb2TO');

$user = User::findBySqidOrFail('use_invalid');

$users = User::query()
    ->whereSqid('use_A3EyoEb2TO')
    ->get();

$users = User::query()
    ->whereSqidIn('id', ['use_A3EyoEb2TO'])
    ->get();

$users = User::query()
    ->whereSqidNotIn('id', ['use_A3EyoEb2TO'])
    ->get();

// GET /users/use_A3EyoEb2TO
Route::get('users/{user}', function (User $user) {
    return "Hello $user->name";
});

use RedExplosion\Sqids\Model;

$model = Model::find('use_A3EyoEb2TO');

use RedExplosion\Sqids\Model;

$model = Model::findOrFail('use_A3EyoEb2TO');
shell
php artisan vendor:publish --provider="RedExplosion\Sqids\SqidsServiceProvider"