简体   繁体   English

Laravel帮助程序文件不起作用?

[英]Laravel helper files not working?

Seems like my helper file app/helpers.php isn't working at all. 似乎我的助手文件app / helpers.php根本无法正常工作。 I just get a Call to undefined function App\\Http\\Controllers\\test() error when I try to call functions in it even though it has the exact same setup (i think?) as another project that works. 当我尝试在其中调用函数时,即使它与另一个可以正常工作的项目具有完全相同的设置(我认为呢),我也只是收到Call to undefined function App\\Http\\Controllers\\test()调用错误。

All the things that seemed to help everyone else with this problem doesn't work for me. 似乎可以帮助其他人解决此问题的所有事情对我都不起作用。 Ie, adding the file to the composer.json, dumping autoload and so on. 即,将文件添加到composer.json,转储自动加载等。

Content of helper file: 帮助文件的内容:

<?php

function test()
{
    dd(":(");
}

Calling the function from a Controller: 从控制器调用函数:

public function test()
{
    test();
}

You need to load the file with custom helpers . 您需要使用自定义帮助程序加载文件 For example, if its name is helper and it's in the app directory: 例如,如果其名称为helper且位于app目录中:

"autoload": {
    ....
    "files": [
        "app/helper.php"
    ]
},

Also, run the composer du command after that. 另外,在那之后运行composer du命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM