Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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

yoshinyan
Webアプリケーションエンジニア。 PHP/Laravel/JavaScript/Vue.js/Ruby/Rails
https://yoshinyan99.hatenablog.com/
yyphp
PHPerが毎週集まり、ざっくばらんに情報交換する雑談コミュニティ
https://yyphp.connpass.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away