在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
也可以在 app\Providers\AppServiceProvider.php
public function boot() { \Carbon\Carbon::setLocale('zh'); /** * 加載自定義函數庫 */ require app_path('Common/functions.php');