Search code examples
phplaravellaravel-7

laravel 7 , blade file can not find function


I have inherited some legacy code and I am trying to get it to work on a dev server. It works fine on the prod server. I am a laravel noob.

I have almost everything working. (I have locked all the versions in composer.json, to match the working site)

The last thing that is failing is this line :

<img src="{{ asset(GetProfilePicLanding())}}" class="img-responsive">

I get the errorCall to undefined function GetProfilePicLanding()

The blade file is in resources/views/index.blade.php

The function GetProfilePicLanding() is in app/helper.php

I can not imagine why the two servers running same code would be different in finding this file

I was looking at adding something like @include('app/helper') but then i have to modify the conf/view file.

I am trying not to modify the code itself if possible from prod.

Would love any ideas or how best to debug this.

thanks for any help


Solution

  • Assuming your helper.php file looks something like this:

    <?php
    
    if (!function_exists('helper1')) {
        function helper1($string)
        {
            return ...;
        }
    }
    
    if (!function_exists('helper2')) {
        function helper2()
        {
            return ...;
        }
    }
    
    // and so on
    

    You can add a line in your composer.json file to autoload it.

        ...
        "autoload": {
            "files": [
                "app/helper.php"
            ],
            "psr-4": {
                "App\\": "app/",
                "Database\\Factories\\": "database/factories/",
                "Database\\Seeders\\": "database/seeders/"
            }
        },
        ...
    

    You might need to run composer update after this though.