把所有的『自定义辅助函数』存放于 bootstrap/helpers.php 文件中,创建这个文件,并且放入如下内容:
<?php
function test_helper() {
return 'OK';
}
打开 composer.json 文件,并找到 autoload 段,将其修改为:
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
},
"files": [
"bootstrap/helpers.php"
]
},
然后再在 Vagrant 中 项目根目录执行:
$ composer dumpautoload
然后再次进入 tinker 执行 test_helper 函数,可以看到有了正常返回: