mbo's avatar
Level 3

Call to undefined function in helper file.

I deployed my local app via github to forge/do. (from local to production)

the deployment went well. But when i try to reach a page it gives the following error:

[2020-03-26 17:13:54] production.ERROR: Call to undefined function autoVer() (View: /home/forge/default/resources/views/partials/standaard/lxx/_head.blade.php) (View: /home/forge/default/resources/views/partials/standaard/xx/_head.blade.php) (View: /home/forge/default/resources/views/partials/standaard/xx/_head.blade.php) {"exception":"[object] (ErrorException(code: 0): Call to undefined function autoVer() (View: 

It seems that laravel is not able to find a the function. In local development (mac/valet) i don't get the error.

the function is located in a helper file. Located in the folder helpers.

i got a file HelperServiceProvider where i register the total helper folder.

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class HelperServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
          foreach (glob(app_path().'/Helpers/*.php') as $filename){
           require_once($filename);
          }
    }
}

It looks like it doesn't work in production?

What can i do to solve the issue?

thanks for the reactions.

0 likes
7 replies
bobbybouwmann's avatar

This is probably because you execute this method before the ServiceProvider is loaded. A better approach is to autoload the files in your composer.json

"autoload": {
    "psr-4": {
        "App\": "app/"
    },
    "classmap": [
        "database/seeds",
        "database/factories",
        "app/Helpers"
    ]
},
mbo's avatar
Level 3

Bobbybouwmann,

thanks for your reply.

I thought this was the solution. But by ending the provider i didn't work on my local machine as well. So it seems that the classmap in composer.jon does not work. Any idea how to solve this?

To make sure is it not the function that is not working i called some other functions as well.

i also run composer dump autoload. Did not solve it either.

thanks for the reply

bobbybouwmann's avatar
Level 88

You can also try to load each file one by one

"autoload": {
    "psr-4": {
        "App\": "app/"
    },
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "files": [
        "app/Helpers/app.php"
    ]
},

Make sure you run composer autoload after changing the file.

1 like
Snapey's avatar

make sure you don't have any letter case issues. On your local environment. you are probably operating case-insensitive, but on your production system helpers and Helpers are different things

mbo's avatar
Level 3

Bobby,

thanks for the reaction. That is also a solution indeed. I like to have it by a folder. But that is not going to work for now. Maybe it is connect to another issue i have with the fact that my env file does give any values to other files as well. Thanks anyway.

mbo's avatar
Level 3

Snapey, thanks for the reply. Im wondering: is there a way to set my local development to case sensitive?

i develop on: mac > valet.

thanks!

creativewebcode's avatar

You just need to register "App\Providers\HelperServiceProvider::class" inside config/app.php under providers sections

Please or to participate in this conversation.