1. Go to this page and download the library: Download istiak-tridip/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/ */
istiak-tridip / laravel-sqids example snippets
use Istiak\Sqids\Concerns\HasSqids;
class User extends Model
{
use HasSqids;
}
$user = User::query()->first();
echo $user->refid; // Outputs the Sqid for the model's ID
// Throws an exception on failure
$id = $user->sqids()->decode($user->refid);
// Returns null on failure
$id = $user->sqids()->decodeOrNull($user->refid);
// Find a single model by Sqid
$user = User::query()->whereSqid($sqid)->first();
// Find multiple models by Sqids
$users = User::query()->whereSqidIn([$sqid1, $sqid2])->get();
// GET /invoices/86Rf07xd4z
Route::get('/invoices/{record}', function (Invoice $record) {
return $record->number;
});
use Istiak\Sqids\Support\Config;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Config::generateNumericIds();
}
}