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.
Download luilliarcec/laravel-username-generator
More information about luilliarcec/laravel-username-generator
Files in luilliarcec/laravel-username-generator
Package laravel-username-generator
Short Description Laravel Username Generator is a package that allows the versatile generation of user names, has a simple integration with Laravel.
License MIT
Homepage https://github.com/luilliarcec/laravel-username-generator
Informations about the package laravel-username-generator
Laravel Username Generator
Laravel Username Generator is a package that allows the versatile generation of user names, 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:
We have improved many things so we have decided to launch a new version 2.0.
Please follow this guide if you are going to update to the new version.
Now in AppServiceProvider, add the basic or default configuration to use.:
Note that now you are free to configure as you like from the Facade. You also have the possibility to tell the package, to check with deletions in the model provided.
Upgrade
Upgrading to the new version is as easy as:
- Update package
- Delete the configuration file
- And set the configuration from your AppServiceProvider.
Usage
Once configured, you can use the Facade Luilliarcec\LaravelUsernameGenerator\Facades\Username
in the following way:
If you want to change the type of case I can do it online, for example:
This will implicitly take the settings from your AppServiceProvider
and replace it with the one you provide inline.
New Features
One of the features that I liked to add the most is the possibility that you can create your own driver.
Support for customs drivers
You can create a class that implement the
interface Luilliarcec\LaravelUsernameGenerator\Contracts\UsernameDriverContract
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:
Usage
Support for multiple models
That's right, you now have the ability to generate usernames for different models. Just pass the space name of your model to the setModel function and you can even s et the column to use to check for existing usernames, for example:
Support for softdelete
And last but not least, if you want your generator to verify usernames with deleted users, now you can with the withTrashed function.
But if you don't use softDelete or don't want to check with deleted users, use the withoutTrashed method. (By default this method is already applied)
¡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 genarator 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 pefix 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
or
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
- Luis Andrés Arce C.
- All Contributors
License
The MIT License (MIT). Please see License File for more information.