Home > PHP Framework > Laravel > How to add helpers.php in laravel framework? (detailed explanation of steps)

How to add helpers.php in laravel framework? (detailed explanation of steps)

不言
Release: 2018-08-23 10:50:32
Original
3426 people have browsed it

本篇文章给大家带来的内容是关于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"
    ]
},
Copy after login

3、执行命令 composer dump-autoload

4、在app/Http/helpers.php中定义方法

if (! function_exists('test')) {    
function test()
    {
       # code something
    }
}
Copy after login

然后,我们就可以方便在程序中直接使用方法了 ……

public function testHelper(){
    $testHelper = test();
}
Copy after login

相关推荐:

php Laravel 框架之建立后台文件夹 二

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template