輔助函數文件位於/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