Home >PHP Framework >Laravel >How to add helpers.php in laravel framework? (detailed explanation of steps)
本篇文章给大家带来的内容是关于laravel框架中如何添加helpers.php?(步骤详解),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
1、创建 app/Http/helpers.php文件
2、修改 compose.json文件
"autoload": { "classmap": [ "database/seeds", "database/factories" ], "psr-4": { "App\\": "app/" }, # 添加的 files 键 "files": [ "app/Http/helpers.php" ] },
3、执行命令 composer dump-autoload
4、在app/Http/helpers.php中定义方法
if (! function_exists('test')) { function test() { # code something } }
然后,我们就可以方便在程序中直接使用方法了 ……
public function testHelper(){ $testHelper = test(); }
相关推荐:
Laravel 5框架学习之模型、控制器、视图基础流程,laravel框架
The above is the detailed content of How to add helpers.php in laravel framework? (detailed explanation of steps). For more information, please follow other related articles on the PHP Chinese website!