将 Laravel 从 5.6 升级到 6.0 后,调用未定义的 str_random() 函数不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/58163406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:22:26  来源:igfitidea点击:

After upgrading Laravel from 5.6 to 6.0, Call to undefined str_random() function not working

phplaravellaravel-6laravel-helperlaravel-upgrade

提问by Vishal Srivastava

I have upgraded Laravel from 5.6 to 6.0. Previously, default helper functions were running fine on the controllers, but now it says "undefined." In my controller, I have used the following.

我已将 Laravel 从 5.6 升级到 6.0。以前,默认的辅助函数在控制器上运行良好,但现在显示“未定义”。在我的控制器中,我使用了以下内容。

$filename = str_random(12);

I am getting the following error.

我收到以下错误。

message: "Call to undefined function App\Http\Controllers\str_random()"

消息:“调用未定义的函数 App\Http\Controllers\str_random()”

I have also used the random()function, and it's saying the same thing.

我也用过这个random()函数,它说的是同样的事情。

Can somebody please guide me on what to do?.

有人可以指导我做什么吗?

I have run commands like:

我已经运行了如下命令:

composer dump-autoload

But I get the same error.

但我得到了同样的错误。

回答by Jignesh Joisar

Likelihood Of Impact: High Laravel 6 Upgrade Guide

影响的可能性:高Laravel 6 升级指南

In Laravel 6 All str_and array_helpers have been moved to the new laravel/helpersComposer package and removed from the framework. If desired, you may update all calls to these helpers to use the Illuminate\Support\Strand Illuminate\Support\Arrclasses. Alternatively, you can add the new laravel/helperspackage to your application to continue using these helpers:

在 Laravel 6 中 Allstr_array_helpers 已移至新的laravel/helpersComposer 包并从框架中删除。如果需要,您可以更新对这些助手的所有调用以使用Illuminate\Support\StrIlluminate\Support\Arr类。或者,您可以将新laravel/helpers包添加到您的应用程序以继续使用这些帮助程序:

composer require laravel/helpers

If don't want to add Package then Used StrAnd ArrClasses.

如果不想添加包然后使用StrArr类。

For Example :

例如 :

Str::random(12)

https://laravel.com/docs/master/helpers#method-str-random

https://laravel.com/docs/master/helpers#method-str-random

回答by Hitendra Singh Shekhawat

Add the following string library.

添加以下字符串库。

use Illuminate\Support\Str;

now you can use it as below.

现在你可以使用它如下。

$filename = Str::random(40)

alternatively, install the following package.

或者,安装以下软件包。

composer require laravel/helpers