问题描述
我已将Laravel从5.6升级到6.0.以前,默认的辅助功能在控制器上运行良好,但现在显示为"未定义".在我的控制器中,我使用了以下内容.
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.
$filename = str_random(12);
我遇到以下错误.
我还使用了 random()
函数,它的意思是相同的.
I have also used the random()
function, and it's saying the same thing.
有人可以指导我该怎么做吗.
Can somebody please guide me on what to do?.
我有运行命令,例如:
composer dump-autoload
但是我遇到了同样的错误.
But I get the same error.
推荐答案
在Laravel 6中,所有 str _
和 array _
帮助器都已移至新的 laravel/helpers
Composer程序包中,并且已从框架.如果需要,您可以更新对这些助手的所有调用,以使用 Illuminate \ Support \ Str
和 Illuminate \ Support \ Arr
类.另外,您可以将新的 laravel/helpers
包添加到您的应用程序中,以继续使用这些助手:
In Laravel 6 All str_
and array_
helpers have been moved to the new laravel/helpers
Composer package and removed from the framework. If desired, you may update all calls to these helpers to use the Illuminate\Support\Str
and Illuminate\Support\Arr
classes. Alternatively, you can add the new laravel/helpers
package to your application to continue using these helpers:
composer require laravel/helpers
如果不想添加包,则使用 Str
和 Arr
类.
If don't want to add Package then Used Str
And Arr
Classes.
例如:
Str::random(12)
https://laravel.com/docs/master/helpers#method-随机
这篇关于将Laravel从5.6升级到6.0后,对未定义的str_random()函数的调用不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!