6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 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]
(https://itsolutionstuff.com/post/laravel-58-new-features-listexample.html)

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?