PHPackages                             levizwannah/laravel-username-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. levizwannah/laravel-username-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

levizwannah/laravel-username-generator
======================================

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

v1.0.0.0(3mo ago)022MITPHPPHP ^8.2|^8.3|^8.4

Since Jan 20Pushed 3mo agoCompare

[ Source](https://github.com/levizwannah/laravel-username-generator)[ Packagist](https://packagist.org/packages/levizwannah/laravel-username-generator)[ Docs](https://github.com/levizwannah/laravel-username-generator)[ RSS](/packages/levizwannah-laravel-username-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Laravel Username Generator (A fork for compatibility with Laravel 12)
=====================================================================

[](#laravel-username-generator-a-fork-for-compatibility-with-laravel-12)

[![Latest Version on Packagist](https://camo.githubusercontent.com/61a204dc2f933fb75ad0957679118ac5bbd88f51112579b72cae99a6af659642/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6576697a77616e6e61682f6c61726176656c2d757365726e616d652d67656e657261746f722e737667)](https://packagist.org/packages/levizwannah/laravel-username-generator)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c4d1c57459720a8cfc51b2369af0ec4582c7ecc4149ce884410e986a55ed9827/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c6576697a77616e6e61682f6c61726176656c2d757365726e616d652d67656e657261746f722f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/levizwannah/laravel-username-generator/actions?query=workflow%3Arun-tests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/78970fb64be243481dd2b6eb6ce5150ae6311109662624fe519b3aeff7c6e7d7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c6576697a77616e6e61682f6c61726176656c2d757365726e616d652d67656e657261746f722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/levizwannah/laravel-username-generator/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/1e8272fb8f36499684e5006d9319d29b7171968496860d7156b0bda089b15a1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6576697a77616e6e61682f6c61726176656c2d757365726e616d652d67656e657261746f72)](https://packagist.org/packages/levizwannah/laravel-username-generator)

[![Buy Me A Coffee](https://camo.githubusercontent.com/9a769e616ce78645bf51d12e4179cfbfd72fb413722b284e0be3ec3c75a86010/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f64656661756c742d6f72616e67652e706e67)](https://www.buymeacoffee.com/luilliarcec) (Original Package Creator)

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

You can generate from the name of the user, taking into account that you do not use more than two names and two surnames in total. It can also be generated from the user's email.

Installation
------------

[](#installation)

You can install the package via composer:

### Version 5 was rewritten to be supported as a usable trait within your models.

[](#version-5-was-rewritten-to-be-supported-as-a-usable-trait-within-your-models)

### Please follow this guide if you are going to update to the new version.

[](#please-follow-this-guide-if-you-are-going-to-update-to-the-new-version)

```
composer require levizwannah/laravel-username-generator
```

Upgrade
-------

[](#upgrade)

Upgrading to the new version is as easy as:

- Update package
- Delete the old configuration from your AppServiceProvider.

Usage
-----

[](#usage)

Add the Trait `LeviZwannah\LaravelUsernameGenerator\Concerns\HasUsername` to your Eloquent models in the use username.

Remember that you must have a field in your table where you can store the `username`, preferably it is recommended make this field `unique`.

```
use Illuminate\Database\Eloquent\Model;
use LeviZwannah\LaravelUsernameGenerator\Concerns\HasUsername;

class User extends Model
{
    use HasUsername;
}
```

Within your model, you configure the username generator options.

By default, you must configure the field where the username will be stored and searched:

```
protected function getUsernameColumn(): string
{
    return 'my_username_column';
}
```

In addition to where the value will be extracted to generate the username:

```
protected function getName(): string
{
    // This is the value, not the field name.
    return $this->name;
}
```

**Remember the value of name cannot be empty `''`, this will throw an exception, just like using a driver incorrect for an incorrect value, for example using the `Name` driver to generate usernames from an email.**

With this, your model will now be configured to work with usernames.

### Additional settings

[](#additional-settings)

If your model stores the first and last name separately, you can set the `getLastName` function, so that it returns the value of your model's last name.

```
protected function getLastName(): ?string
{
    // This is the value, not the field name.
    return $this->last_name;
}
```

By default, the trait uses the driver `LeviZwannah\LaravelUsernameGenerator\Drivers\Name`. This is modifiable overriding the `getUsernameDriver` method.

```
use LeviZwannah\LaravelUsernameGenerator\Drivers\Email;

protected function getUsernameDriver(): DriverContract
{
    return new Email();
}
```

By default, usernames are converted to lowercase. But if you want, convert them to uppercase or apply some logic or add a prefix or suffix, before the repeat search is processed, you can use the function `transformUsername`, this function receives the username as a parameter and returns a string.

```
protected function transformUsername(string $username): string
{
    return mb_strtoupper($username, 'UTF-8');
}
```

#### Support for customs drivers

[](#support-for-customs-drivers)

You can create a class that implement the interface `LeviZwannah\LaravelUsernameGenerator\Contracts\DriverContract`and inside that class you can write all the logic to generate your username, remember to implement the make method that will be responsible for returning the username, for example:

```
namespace App\Support\Username\Drivers;

use LeviZwannah\LaravelUsernameGenerator\Contracts\DriverContract;

class CustomDriver implements DriverContract
{
    public function make(string $name, string $lastname = null): string
    {
        // your code
    }
}
```

¡Important!
-----------

[](#important)

Remember that like previous versions it is very important that you provide an Eloquent Model together with the column that stores the username. This is so that the package provides you with an alternate username if it is already in use.

Skipping this step will cause an exception `UsernameGeneratorException` or that the generator does not work properly

Examples
--------

[](#examples)

Assume you have a user with the username `larcec`

```
$model = User::create(['name' => 'Luis Andrés Arce Cárdenas']);

$model->username; // larcec
```

When using the package to generate the username, it will search thanks to Eloquent, in the database and will buy if that username already exists, if it exists, a suffix will be added to the username.

The result would be as follows.

```
$model = User::create(['name' => 'Luciano Carlos Arce Cajamarca']);

$model->username; // larcec1
```

Laravel Username Generator uses a convention for the creation of user names, takes the `first letter of the first name`, takes the `first last name`, and finally the `first letter of the second last name`

However, Laravel Username Generator is so versatile that it can receive `only 1 name`, `1 name and 2 surnames`, and can even use the auxiliary surname parameter to pass the `two surnames separately`, in the following ways.

```
$model = User::create(['first_name' => 'Luis Andrés', 'last_name' => 'Arce Cárdenas']);
$model = User::create(['name' => 'Luis Andrés Arce Cárdenas']);
// This will generate the following username: larcec

$model = User::create(['first_name' => 'Luis', 'last_name' => 'Arce']);
$model = User::create(['name' => 'Luis Arce']);
// This will generate the following username: larce

$model = User::create(['first_name' => 'Luis', 'last_name' => 'Arce Cárdenas']);
$model = User::create(['name' => 'Luis Arce Cárdenas']);
// This will generate the following username: larcec
```

Keep these examples in mind, since passing a value of more or more than two names or two surnames without following the convention may cause an exception

Finally, you can use the `email` driver, which will receive an email as the first and only parameter and take the user's email and use it as a username.

```
$model = User::create(['email' => 'luilliarcec@gmail.com']);
// This will generate the following username: luilliarcec
```

Testing
-------

[](#testing)

Can use docker-compose to run

```
docker-compose exec app composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Luis Andrés Arce C.](https://github.com/luilliarcec)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance79

Regular maintenance activity

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

113d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/56189552?v=4)[Levi Kamara Zwannah](/maintainers/levizwannah)[@levizwannah](https://github.com/levizwannah)

---

Top Contributors

[![luilliarcec](https://avatars.githubusercontent.com/u/27895611?v=4)](https://github.com/luilliarcec "luilliarcec (169 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![levizwannah](https://avatars.githubusercontent.com/u/56189552?v=4)](https://github.com/levizwannah "levizwannah (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

laravellaravel 12generatorusernameluilliarceclaravel-username-generator

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/levizwannah-laravel-username-generator/health.svg)

```
[![Health](https://phpackages.com/badges/levizwannah-laravel-username-generator/health.svg)](https://phpackages.com/packages/levizwannah-laravel-username-generator)
```

###  Alternatives

[luilliarcec/laravel-username-generator

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

1011.8k](/packages/luilliarcec-laravel-username-generator)[lara-zeus/popover

Zeus Popover is filamentphp component to show a Popover with custom content in tables and infolist

2968.2k3](/packages/lara-zeus-popover)[lara-zeus/inline-chart

Zeus Inline Chart easily add a chart in filamentPHP table column

2139.9k](/packages/lara-zeus-inline-chart)[lara-zeus/accordion

Zeus Accordion is filamentphp layout component to group components

11122.8k2](/packages/lara-zeus-accordion)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
