-
Notifications
You must be signed in to change notification settings - Fork 10
Config
Details of all the config options, select one from the list to view more details.
- Unique (
'unique'
) - Minimum Length (
'min_length'
) - Throw an Exception on Too Short (
'throw_exception_on_too_short'
) - Maximum Length (
'max_length'
) - Throw an Exception on Too Long (
'throw_exception_on_too_long'
) - Character Case (
'case'
) - Separator (
'separator'
) - Model (
'model'
) - Username Column (
'column'
) - Validate Characters (
'validate_characters'
) - Allowed Characters (
'allowed_characters'
) - Character Encoding (
'encoding'
) - Convert to ASCII (
'convert_to_ascii'
) - Language (
'language'
) - Generate on Entered Usernames (
'generate_entered_username'
) - Prefer SQL REGEXP Function (
'prefer_regexp'
) - Field Map (
'field_map'
) - Increment Max Attempts (
'increment_max_attempts'
) - Registered Drivers (
'drivers'
) - Alternate Dictionary (
'dictionary'
)
Key: 'unique'
Type: Boolean
Default Value:
false
Description:
Should the username be unique to the Model class?
Key: 'min_length'
Type: Integer
Default Value:
0
Description:
What is the minimum length a username needs to be?
Notes:
Set to 0
to not enforce.
Key: 'throw_exception_on_too_short'
Type: Boolean
Default Value:
false
Description:
Throw a UsernameTooShortException
if username is shorter than the 'min_length'
?
Notes:
Set to false
to automatically pad the username to make it longer.
Key: 'max_length'
Type: Integer
Default Value:
0
Description:
What is the maximum length a username can be?
Notes:
Set to 0
to not enforce.
Key: 'throw_exception_on_too_long'
Type: Boolean
Default Value:
false
Description:
Throw a UsernameTooLongException
if username is longer than the 'max_length'
?
Notes:
Set to false
to automatically reduce the length of the username.
Key: 'case'
Type: String
Default Value:
'lower'
Description:
Function to transform the string's casing.
Suggested:
'lower'
'upper'
'title'
Notes:
- Uses the Illuminate\Support\Str class behind the scenes. You can use any string function that accepts 1 parameter and returns the transformed text.
- Ignore using
'mixed'
(or any other value).
Key: 'separator'
Type: String
*
Default Value:
''
Description:
Character to replace all spaces between words with.
Suggested:
''
'_'
'-'
Notes:
* Should probably be a single character, but can be multiple.
Key: 'model'
Type: String
Default Value:
\App\Models\User::class
Description:
Model to check username's uniqueness against.
Notes:
- Model must use the
FindSimilarUsernames
trait.
Key: 'column'
Type: String
Default Value:
'username'
Description:
Username column to use for unique check on model.
Key: 'validate_characters'
Type: Boolean
Default Value:
true
Description:
Should we validate characters with RegEx? Will use the 'allowed_characters'
as the expression.
Key: 'allowed_characters'
Type: String
*
Default Value:
'a-zA-Z\s '
Description:
Characters (or character sets) that are allowed in the final username. All characters not in this expression are automatically replaced by ''
. If you are using different character sets ('\p{Greek}'
for example) that you want in the final username, be sure to change 'convert_to_ascii'
to false
.
Suggested:
'a-zA-Z\s '
'\p{Latin}\s '
Notes:
* A regular expression, without the exterior quotes.
Key: 'encoiding'
Type: String
Default Value:
'UTF-8'
Description:
Encoding to use with the mb_*
PHP string helpers. 'UTF-8'
is likely fine for most cases.
Key: 'convert_to_ascii'
Type: Boolean
Default Value:
true
Description:
Instead of working with other character sets, convert input to ASCII immediately.
Notes:
Set to false
if you use any other character sets set out in 'allowed_characters'
.
Key: 'language'
Type: String
Default Value:
'en'
Description:
Used when converting the input to ASCII.
Key: 'generate_entered_username'
Type: Boolean
Default Value:
true
Description:
If a user supplies their own username, should it be passed through the generator to make sure all usernames are the same?
Notes:
This only applies if your 'model'
is also using the GeneratesUsernames
trait.
Key: 'prefer_regexp'
Type: Boolean
Default Value:
false
Description:
Prefer using the SQL REGEXP
function for finding similar usernames?
If set to false
the SQL LIKE
function will be used to find similar usernames.
If set to true
the SQL REGEXP
function will attempt to find similar usernames, if that fails, LIKE
will be used.
Key: 'field_map'
Type: Array
Default Value:
[]
Description:
In some cases, your 'model'
field structure won't match that of the driver you're using. In that case you may need to use a field map. Here you can define the driver's field key to what it is on your model.
For example if your model has a fullName
field, since the NameDriver
looks for a name
field:
[
'name' => 'fullName',
]
Key: 'increment_max_attempts'
Type: Integer
Default Value:
100
Description:
If the username fails to become unique after using other methods, the last number will be incremented until a unique value is given, this option limits the amount of attempts it can make.
This is used in a loop so if you put the value too high the execution time may suffer, but this is a last resort attempt to make the username unique.
Key: 'drivers'
Type: Array
Default Value:
[
'name' => \TaylorNetwork\UsernameGenerator\Drivers\NameDriver::class,
'email' => \TaylorNetwork\UsernameGenerator\Drivers\EmailDriver::class,
]
Description:
All the regiestered drivers and their keys.
The first item in this array is the default driver used.
Anything in this array can be used by the setDriver('driverKey')
method or the ::usingDriverKey()
static method.
Key: 'dictionary'
Type: Array
Default Value:
[
'adjectives' => [],
'nouns' => [],
]
Description:
If you don't want to use the default word lists, add your own 'nouns'
and 'adjectives'
word lists here.
Default word lists from alenoir/username-generator