laravel 5 自定义全局函数,怎么弄呢?

在app/Helpers/(目录可以自己随便来) 下新建一个文件 functions.php
在functions.php 中加入这个方法
然后在
bootstrap/autoload.php 中添加

require __DIR__.'/../app/Helpers/functions.php';

 或者在composer.json 中的 autoload 下增加

"files": [
    "app/Helpers/functions.php"
]
...
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\": "app/"
    },
    "files": [
        "app/helpers/functions.php"
    ]
},
 
...

 然后执行:

composer dump-auto
 
 
也可以在 appProvidersAppServiceProvider.php
 
public function boot() {
    CarbonCarbon::setLocale('zh');
    /**
     * 加载自定义函数库
     */
    require app_path('Common/functions.php');

 转载;https://blog.csdn.net/zl20117/article/details/53537009

原文地址:https://www.cnblogs.com/lxwphp/p/9473504.html