laravel 如何引入自己的函数或类库

例如在app下建一个Common文件夹 在Common下建一个function.php 放入公共函数

例如:
function test(){
   echo 'this is a test';
}
在项目目录下composer.json中加入

"autoload": {
    "files":[
        "app/Common/function.php"
    ]
}

在项目中执行

composer dump-autoload

 在控制器的某个方法中调用

public function aa(){
    test();    
}

猜你喜欢

转载自blog.csdn.net/dabao87/article/details/82986824