yooper/nicknames
Laravel package for generating and managing nicknames in your app. Provides simple APIs to create unique, friendly aliases for users or records, with easy integration into existing models and workflows.
Start by installing the package via Composer: composer require yooper/nicknames. As the last release was in 2017, verify compatibility with your Laravel version (tested up to Laravel 5.5–5.8). After installation, publish the config file (php artisan vendor:publish --provider="Yooper\Nicknames\NicknamesServiceProvider"), then open config/nicknames.php to review defaults. The most common first use case is generating clean, unique nicknames for new users—e.g., converting "John Doe" into "johndoe" or "john-doe".
The simplest programmatic usage is:
use Yooper\Nicknames\NicknameGenerator;
$generator = new NicknameGenerator();
$nickname = $generator->generate('Alice Johnson'); // e.g., 'alicejohnson'
Check src/NicknameGenerator.php and config/nicknames.php for immediate customization.
creating or saving) to auto-generate a unique nickname before persistence:
public static function boot()
{
parent::boot();
static::creating(function ($user) {
if (!$user->nickname) {
$user->nickname = app(NicknameGenerator::class)->generate($user->name);
}
});
}
$nickname = $generator->generate([
'name' => 'Dr. Jane Smith',
'seed' => 'jsmith',
'maxAttempts' => 5,
]);
NicknameStrategy to enforce domain-specific rules (e.g., ban certain keywords, enforce length limits, prepend department codes). Register via config.Illuminate\Support\Str usage pre-6.x).maxAttempts (configurable) before throwing—always wrap generate() in a try/catch or fallback if uniqueness is critical.utf8mb4_general_ci) to avoid false uniqueness failures.SanitizeStrategy, or override collision suffix logic by extending CollisionStrategy. Use config/nicknames.php to swap strategies without touching vendor code.NicknameGenerator in unit tests—avoid real generation during tests to ensure deterministic behavior. Use ->generate('seed', ['dryRun' => true]) if the class supports it (check code).How can I help you explore Laravel packages today?