Download the PHP package luilliarcec/laravel-username-generator without Composer

On this page you can find all versions of the php package luilliarcec/laravel-username-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-username-generator

Laravel Username Generator

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Buy Me A Coffee

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

You can install the package via composer:

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.

Upgrade

Upgrading to the new version is as easy as:

Usage

Add the Trait Luilliarcec\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.

Within your model, you configure the username generator options.

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

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

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

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.

By default, the trait uses the driver Luilliarcec\Laravel Username Generator\Drivers\Name. This is modifiable overriding the getUsernameDriver method.

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.

Support for customs drivers

You can create a class that implement the interface Luilliarcec\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:

¡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

Assume you have a user with the 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.

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.

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.

Testing

Can use docker-compose to run

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

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

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-username-generator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2|^8.3
laravel/framework Version ^10.0|^11.0
spatie/laravel-package-tools Version ^1.14.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package luilliarcec/laravel-username-generator contains the following files

Loading the files please wait ....