2017 © Pedro Peláez
 

library super-random

Allows for easy unique code generation, is database aware for Laravel Applications.

image

thejawker/super-random

Allows for easy unique code generation, is database aware for Laravel Applications.

  • Monday, February 19, 2018
  • by thejawker
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Generate Database Aware Unique Codes For Laravel

Latest Version on Packagist Build Status Quality Score Total Downloads, (*1)

Nice and fluent way to create truly unique codes or tokens., (*2)

Installation

Require the package from Composer:, (*3)

``` bash composer require thejawker/super-random, (*4)


As of Laravel 5.5 it will magically register the package. ## Usage Just simple call the generate method on SuperRandom Facade or the handy shortcut helper function. ```php $code = SuperRandom::generate(); echo $code; // $code = superRandom();

Examples:

Database Aware

Often you don't want more than one of the same codes or tokens to be present in your database. Although it's easy to compare to the database it is annoying having to re-implement this all over the place. By specifying the table.column in the for method you can easily make it entry aware., (*5)

ConcertTicket::create([
    'band' => 'DYSSEBIA',
    'code' => SuperRandom::for(ConcertTicket::class)->generate()
]);

// Or more explicit:
ConcertTicket::create([
    'band' => 'DYSSEBIA',
    'code' => SuperRandom::for('concerts.code')->generate()
]);

Length

You can specify the length as follows:, (*6)

ConcertTicket::create([
    'band' => 'DYSSEBIA',
    'code' => SuperRandom::length(12)->generate()
]);

Allowed Chars

You can specify the allowed chars as follows:, (*7)

ConcertTicket::create([
    'band' => 'DYSSEBIA',
    'code' => SuperRandom::chars('abc123')->generate()
]);

By default we only include numbers and UPPERCASE characters with the exclusion of: 1, I, O, 0 since they look a lot alike and you don't want your users to guess., (*8)

Full Config

You can alternatively set the config right on the generate() method., (*9)

ConcertTicket::create([
    'band' => 'DYSSEBIA',
    'code' => SuperRandom::generate([
        'table' => 'concerts',
        'column' => 'code',
        'length' => 15,
        'chars' => 'abc123'
    ])
]);

Test

bash composer test, (*10)

License

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

The Versions

19/02 2018

dev-master

9999999-dev https://github.com/thejawker/super-random

Allows for easy unique code generation, is database aware for Laravel Applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

unique random code-generator thejawker database-aware-unique-code-generator token-generator

19/02 2018

v1.0.2

1.0.2.0 https://github.com/thejawker/super-random

Allows for easy unique code generation, is database aware for Laravel Applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

unique random code-generator thejawker database-aware-unique-code-generator token-generator

15/02 2018

v1.0.1

1.0.1.0 https://github.com/thejawker/super-random

Allows for easy unique code generation, is database aware for Laravel Applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

unique random code-generator thejawker database-aware-unique-code-generator token-generator

12/02 2018

v1.0.0

1.0.0.0 https://github.com/thejawker/super-random

Allows for easy unique code generation, is database aware for Laravel Applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

unique random code-generator thejawker database-aware-unique-code-generator token-generator

09/02 2018

v0.0.1

0.0.1.0 https://github.com/thejawker/super-random

Allows for easy unique code generation, is database aware for Laravel Applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

unique random code-generator thejawker database-aware-unique-code-generator token-generator