hidehalo/nanoid-php
Secure, URL-friendly unique ID generator for PHP inspired by nanoid. Generates 21‑char IDs with UUIDv4-like collision probability, supports custom alphabets/lengths, and lets you plug in your own random bytes generator for extra control.
random_bytes()), preserving protection against predictability attacks.Str::uuid() or DB::raw('UUID()') where shorter alphanumeric IDs are preferred, but now with PHP 8.4 compatibility and stricter version constraints.extract() or non-type-safe functions).Nanoid for:
$nanoid->length → use typed properties).== vs. ===).Nanoid.Nanoid usage trigger warnings in PHP 8.4? Test with:
$nanoid = new \Hidehalo\Nanoid\Nanoid(['length' => 10]);
$id = $nanoid->generate(); // Check for E_DEPRECATED
$nanoid->customProperty)? Update to typed properties or named args.Nanoid with PHP <7.1? Plan a phased upgrade.php -v
composer.json:
"hidehalo/nanoid": "^2.0"
composer update hidehalo/nanoid
php.ini:
error_reporting = E_ALL | E_DEPRECATED
Nanoid usage in staging. Fix warnings (e.g., replace dynamic properties with named args):
// Before (may trigger warnings in PHP 8.4)
$nanoid = new \Hidehalo\Nanoid\Nanoid();
$nanoid->length = 10;
// After (recommended)
$nanoid = new \Hidehalo\Nanoid\Nanoid(['length' => 10]);
Str::uuid()/DB::raw('UUID()') as before.Nanoid for deprecation warnings.$app->bind(Nanoid::class, function () {
return new \Hidehalo\Nanoid\Nanoid(config('nanoid.settings'));
});
'nanoid' => [
'settings' => [
'alphabet' => '0123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz',
'length' => 21,
],
],
Nanoid as before, but test with PHP 8.4’s strict type system:
$mock = $this->createMock(Nanoid::class);
$mock->method('generate')->willReturn('test123');
$this->app->instance(Nanoid::class, $mock);
How can I help you explore Laravel packages today?