Published on November 16, 2016
random helper method generates a random string of the specified
$length. This method internally uses the OpenSSL function
openssl_random_pseudo_bytes, and therefore requires the OpenSSL extension to be installed and configured.
The signature for the
random helper method is:
random($length = 16)
RuntimeException will be thrown if a call is made to
random without the OpenSSL extension installed.
It should also be noted that the
random method remove the following characters:
The following examples show sample output. Because the intention of the
random method is to generate a random string, any output you get will likely be different:
1use Illuminate\Support\Str;23// XHJtXFOa5Jt8B48z4echo Str::random();56// z50fdgeBrmoJRBh77echo Str::random();89// 2bXJNUcZVdtZfUUzbEgfvvaawOCfOgvK10echo Str::random(32);
str_random($length = 16)
str_random function is a shortcut to calling
Str::random. This function is declared in the global namespace.
Learning text parsing, manipulation, encoding and more through the Laravel string helpers.
Published on April 11, 2018
Published on November 30, 2017
Published on November 20, 2016