Slimez
Slimez

Reputation: 607

Laravel helper files not working?

Seems like my helper file app/helpers.php isn't working at all. 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.

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.

Content of helper file:

<?php

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

Calling the function from a Controller:

public function test()
{
    test();
}

Upvotes: 8

Views: 12057

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163758

You need to load the file with custom helpers. For example, if its name is helper and it's in the app directory:

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

Also, run the composer dump-autoload command after that.

Upvotes: 14

Related Questions