PHP code example of taylornetwork / username-suggester

1. Go to this page and download the library: Download taylornetwork/username-suggester library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

taylornetwork / username-suggester example snippets


$suggester = new \TaylorNetwork\UsernameSuggester\Suggester();

$suggester->suggest(); // Returns a collection of random unique usernames

$suggester->suggest('test user'); // Returns a collection of unique usernames based on the name 'test user'

$suggester->setDriver('random');

$suggester->setAmount(10);

$suggester->setGeneratorConfig([
    'separator' => '*',
]);

$suggester->suggest();

$suggester->suggest('test user');

$suggester->setDriver('random')->setAmount(5)->suggest('test user');

UsernameSuggester::suggest();

namespace App\SuggesterDrivers;

use TaylorNetwork\UsernameSuggester\Drivers\BaseDriver;

class CustomDriver extends BaseDriver
{
    public function makeUnique(string $username): string
    {
        return $username;
    }
}

'drivers' => [
    'custom' => CustomDriver::class,
    // ...
],

UsernameSuggester::setDriver('custom')->suggest();
bash
$ php artisan vendor:publish --provider="TaylorNetwork\UsernameSuggester\UsernameSuggesterProvider"