Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Username Generator

Laravel Username Generator Laravel Package

luilliarcec/laravel-username-generator

Laravel Username Generator creates unique, customizable usernames for Laravel apps from names, emails, or custom strings. It handles collisions, supports configurable patterns and validation, and integrates easily with Eloquent models and registration flows.

View on GitHub
Deep Wiki
Context7

Laravel Username Generator is a package that allows the versatile generation of user names, has a simple integration with Laravel.

Frequently asked questions about Laravel Username Generator
How do I install and set up luilliarcec/laravel-username-generator in a Laravel app?
Install it with Composer using composer require luilliarcec/laravel-username-generator, and pin the constraint to ^6.0.1 rather than ^6.0.0. Then add the HasUsername trait to the Eloquent model that should receive the generated username and confirm which source attribute the trait derives from. There are no service providers, config publishing, or queue workers required for the core behavior, so integration is essentially just the trait plus a unique index on the username column.
Which Laravel and PHP versions does laravel-username-generator support?
The supported PHP and Laravel range is declared in the package's composer.json, so check those constraints against your application's versions before anything else. That check takes only a few minutes and can rule the package out immediately if your stack is older or newer than the maintained matrix. Confirm the matrix is actually exercised in the package CI rather than only listed in metadata.
How does the HasUsername trait generate a username from a name or email?
The trait hooks the Eloquent creating model event and builds the username from a source value such as a name, an email, or a custom string. The exact source attribute matters, so verify on your model which field it reads before relying on it in registration or seeding flows. Because generation is bound to the creating event, it runs automatically on model creation without extra calls in your controllers.
What happens if a generated username already exists in the database?
The package is designed to handle collisions, but the precise strategy is not fully documented, so treat it as something to verify rather than assume. Write a test that creates two records from the same source name and confirm you get a suffixed or otherwise distinct username instead of a raw QueryException from the unique index. Keep your database unique constraint in place regardless, since it is the final guarantee against duplicates.
Does laravel-username-generator regenerate usernames on update as well as on create?
Generation is tied to the creating model event, so the username is produced when a record is first created rather than on every update. That means later changes to the source name or email will not automatically rewrite the username. If you want re-generation on update, add that logic yourself with an observer or a booted hook.
How do I stop the trait from overwriting usernames I set in factories, seeders, or imports?
The trait's contract is to always regenerate the username on create, so any value you set beforehand in a factory, seeder, admin panel, or import will be replaced. Version 6.0.0 tried to add a blank check to prevent this, but it was reverted in 6.0.1 because it broke the package's own tests and could suppress generation. For imports and backfills, bypass model events entirely using saveQuietly, Model::withoutEvents, or a direct query builder insert.
Why should I avoid version 6.0.0 of laravel-username-generator?
Version 6.0.0 introduced a blank guard that was reverted one patch later in 6.0.1, and the maintainer recommends upgrading promptly if you already run it. On 6.0.0 a record created with a pre-populated username could end up with no generated username at all, which is a data-integrity problem rather than a cosmetic one. Pin ^6.0.1 explicitly and do not allow ^6.0.0 to resolve, since that release is a known-bad behavioral set.
Can I customize the username format and validate generated usernames?
Yes. The package supports configurable patterns and validation, so you can shape usernames to your rules for length, allowed characters, and structure. Custom source strings also let you derive usernames from something other than a person's name or email. Test your pattern against edge cases like accented characters and very long names, since transliteration and unicode normalization behavior is not documented.
Will HasUsername conflict with other packages that set usernames, such as registration or slug packages?
It can. Any trait or package that writes the username on create, including auth and registration scaffolds or slug-style traits, will compete with this one, and this trait wins because it regenerates unconditionally on the creating event. Check for trait method collisions on the same model and review observer ordering if existing creating logic reads the username. The simplest resolution is to let this package own the username attribute and remove competing assignment logic.
Is laravel-username-generator actively maintained and safe for production use?
It is a narrow, leaf dependency maintained by a single author, with release notes and changelog entries published in Spanish, which is a friction point for team support and audits. The positive signal is that CI caught the 6.0.0 regression quickly and a corrective patch shipped, which suggests the test suite has real coverage. Before adopting it, review the licence, last commit date, and release cadence, and pin an exact minor range to avoid surprise behavior changes on patch bumps.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
cgv/localized-resource