LoginSignup
6
3

More than 3 years have passed since last update.

laravel5.8でランダム文字列を生成するStr::random()

Last updated at Posted at 2019-08-11

phpstormでlaravel5.8内でstr_random()を使ったらstr_random()みたいになったので、新しいメソッドを探した。

5.8系では、str_random()は、非推奨みたい。

use Illuminate\Support\Str;

$random_str = Str::random(100);

ちなみに5.8でstr_random()を呼ぶと内部でStr::random()が呼ばれるみたい。

vendor/laravel/framework/src/Illuminate/Support/helpers.phpより

if (! function_exists('str_random')) {
    /**
     * Generate a more truly "random" alpha-numeric string.
     *
     * @param  int  $length
     * @return string
     *
     * @throws \RuntimeException
     *
     * @deprecated Str::random() should be used directly instead. Will be removed in Laravel 6.0.
     */
    function str_random($length = 16)
    {
        return Str::random($length);
    }
}

Laravel 5.8 New Features List
*) Deprecated String and Array Helpers Functions

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3