辅助函数文件位于/bootstrap
文件夹下php
function test_helper() {
return 'hello world';
}复制代码
打开 composer.json
文件,并找到 autoload
段,将其修改成:
json
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
},
"files": [
"bootstrap/helpers.php"
]
},复制代码
注意逗号不要多写或者漏写。
bootstrap
composer dumpautoload
重载依赖php artisan tinker
test_helper()
'hello world'复制代码
证实辅助函数自定义成功!bash